drm/i915: Lock the gem_context->active_list while dropping the link
Subsystems (2)
PATCH 1/2 drm/i915: Lock the gem_context->active_list while dropping the link
On unpinning the intel_context, we remove it from the active list inside the GEM context. This list is supposed to be guarded by the GEM context mutex, so remember to take it!
--- drivers/gpu/drm/i915/intel_context.c | 15 +++++++++++---- drivers/gpu/drm/i915/intel_lrc.c | 3 --- drivers/gpu/drm/i915/intel_ringbuffer.c | 3 --- drivers/gpu/drm/i915/selftests/mock_engine.c | 2 -- 4 files changed, 11 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_context.c +11 -4
@@ -165,13 +165,13 @@ intel_context_pin(struct i915_gem_context *ctx,if (err) goto err; +i915_gem_context_get (ctx); +GEM_BUG_ON (ce->gem_context != ctx); +mutex_lock (&ctx->mutex);list_add (&ce->active_link, &ctx->active_engines);mutex_unlock (&ctx->mutex); -i915_gem_context_get (ctx); -GEM_BUG_ON (ce->gem_context != ctx); -smp_mb__before_atomic ();/* flush pin before it is visible */ }
@@ -194,9 +194,16 @@ void intel_context_unpin(struct intel_context *ce)/* We may be called from inside intel_context_pin() to evict another */ mutex_lock_nested (&ce->pin_mutex,SINGLE_DEPTH_NESTING ); -if (likely (atomic_dec_and_test (&ce->pin_count))) +if (likely (atomic_dec_and_test (&ce->pin_count))) { ce->ops->unpin (ce); +mutex_lock (&ce->gem_context->mutex); +list_del (&ce->active_link); +mutex_unlock (&ce->gem_context->mutex); + +i915_gem_context_put (ce->gem_context); + } +mutex_unlock (&ce->pin_mutex); }
drivers/gpu/drm/i915/intel_lrc.c +0 -3
@@ -1277,9 +1277,6 @@ static void execlists_context_unpin(struct intel_context *ce) ce->state->obj->pin_global--;i915_gem_object_unpin_map (ce->state->obj);i915_vma_unpin (ce->state); - -list_del (&ce->active_link); -i915_gem_context_put (ce->gem_context); }static int __context_pin (struct i915_vma *vma)
drivers/gpu/drm/i915/intel_ringbuffer.c +0 -3
@@ -1429,9 +1429,6 @@ static void ring_context_unpin(struct intel_context *ce) {__context_unpin_ppgtt (ce->gem_context);__context_unpin (ce); - -list_del (&ce->active_link); -i915_gem_context_put (ce->gem_context); } static struct i915_vma *
drivers/gpu/drm/i915/selftests/mock_engine.c +0 -2
@@ -125,8 +125,6 @@ static void hw_delay_complete(struct timer_list *t)static void mock_context_unpin (struct intel_context *ce) {mock_timeline_unpin (ce->ring->timeline); -list_del (&ce->active_link); -i915_gem_context_put (ce->gem_context); }static void mock_context_destroy (struct intel_context *ce)
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/2 drm/i915: Hold a reference to the active HW context
For virtual engines, we need to keep the HW context alive while it remains in use. For regular HW contexts, they are created and kept alive until the end of the GEM context. For simplicity, generalise the requirements and keep an active reference to each HW context.
--- drivers/gpu/drm/i915/i915_gem_context.c | 2 +- drivers/gpu/drm/i915/intel_context.c | 6 ++++++ drivers/gpu/drm/i915/intel_context.h | 11 +++++++++++ drivers/gpu/drm/i915/intel_context_types.h | 6 +++++- drivers/gpu/drm/i915/intel_lrc.c | 4 +++- drivers/gpu/drm/i915/intel_ringbuffer.c | 4 +++- drivers/gpu/drm/i915/selftests/mock_engine.c | 7 ++++++- 7 files changed, 35 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
@@ -232,7 +232,7 @@ static void i915_gem_context_free(struct i915_gem_context *ctx)i915_ppgtt_put (ctx->ppgtt);rbtree_postorder_for_each_entry_safe (it, n, &ctx->hw_contexts, node) - it->ops->destroy (it); +intel_context_put (it);kfree (ctx->name);put_pid (ctx->pid);
drivers/gpu/drm/i915/intel_context.c +6 -0
@@ -172,6 +172,7 @@ intel_context_pin(struct i915_gem_context *ctx,list_add (&ce->active_link, &ctx->active_engines);mutex_unlock (&ctx->mutex); +intel_context_get (ce);smp_mb__before_atomic ();/* flush pin before it is visible */ }
@@ -192,6 +193,7 @@ void intel_context_unpin(struct intel_context *ce)return ;/* We may be called from inside intel_context_pin() to evict another */ +intel_context_get (ce);mutex_lock_nested (&ce->pin_mutex,SINGLE_DEPTH_NESTING );if (likely (atomic_dec_and_test (&ce->pin_count))) {
@@ -202,9 +204,11 @@ void intel_context_unpin(struct intel_context *ce)mutex_unlock (&ce->gem_context->mutex);i915_gem_context_put (ce->gem_context); +intel_context_put (ce); }mutex_unlock (&ce->pin_mutex); +intel_context_put (ce); } static void intel_context_retire(struct i915_active_request *active,
@@ -221,6 +225,8 @@ intel_context_init(struct intel_context *ce,struct i915_gem_context *ctx, struct intel_engine_cs *engine) { + kref_init(&ce->ref); + ce->gem_context = ctx; ce->engine = engine; ce->ops = engine->cops;
drivers/gpu/drm/i915/intel_context.h +11 -0
@@ -73,4 +73,15 @@ static inline void __intel_context_pin(struct intel_context *ce)void intel_context_unpin (struct intel_context *ce); +static inline struct intel_context *intel_context_get (struct intel_context *ce) +{ +kref_get (&ce->ref); +return ce; +} + +static inline void intel_context_put (struct intel_context *ce) +{ +kref_put (&ce->ref, ce->ops->destroy); +} +#endif /* __INTEL_CONTEXT_H__ */
drivers/gpu/drm/i915/intel_context_types.h +5 -1
@@ -7,6 +7,7 @@#ifndef __INTEL_CONTEXT_TYPES__#define __INTEL_CONTEXT_TYPES__ +#include <linux/kref.h> #include <linux/list.h> #include <linux/mutex.h> #include <linux/rbtree.h>
@@ -22,7 +23,8 @@ struct intel_ring;struct intel_context_ops {int (*pin)(struct intel_context *ce);void (*unpin)(struct intel_context *ce); -void (*destroy)(struct intel_context *ce); + +void (*destroy)(struct kref *kref); };/*
@@ -36,6 +38,8 @@ struct intel_sseu { };struct intel_context { +struct kref ref; +struct i915_gem_context *gem_context;struct intel_engine_cs *engine;struct intel_engine_cs *active;
drivers/gpu/drm/i915/intel_lrc.c +3 -1
@@ -1236,8 +1236,10 @@ static void __execlists_context_fini(struct intel_context *ce)i915_gem_object_put (ce->state->obj); } -static void execlists_context_destroy (struct intel_context *ce) +static void execlists_context_destroy (struct kref *kref) { +struct intel_context *ce =container_of (kref,typeof (*ce), ref); +GEM_BUG_ON (intel_context_is_pinned (ce));if (ce->state)
drivers/gpu/drm/i915/intel_ringbuffer.c +3 -1
@@ -1349,8 +1349,10 @@ static void __ring_context_fini(struct intel_context *ce)i915_gem_object_put (ce->state->obj); } -static void ring_context_destroy (struct intel_context *ce) +static void ring_context_destroy (struct kref *ref) { +struct intel_context *ce =container_of (ref,typeof (*ce), ref); +GEM_BUG_ON (intel_context_is_pinned (ce));if (ce->state)
drivers/gpu/drm/i915/selftests/mock_engine.c +6 -1
@@ -127,12 +127,16 @@ static void mock_context_unpin(struct intel_context *ce)mock_timeline_unpin (ce->ring->timeline); } -static void mock_context_destroy (struct intel_context *ce) +static void mock_context_destroy (struct kref *ref) { +struct intel_context *ce =container_of (ref,typeof (*ce), ref); +GEM_BUG_ON (intel_context_is_pinned (ce));if (ce->ring)mock_ring_free (ce->ring); + +intel_context_free (ce); }static int mock_context_pin (struct intel_context *ce)
@@ -150,6 +154,7 @@ static int mock_context_pin(struct intel_context *ce)static const struct intel_context_ops mock_context_ops = { .pin = mock_context_pin, .unpin = mock_context_unpin, + .destroy = mock_context_destroy, };
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for series starting with [CI,1/2] drm/i915: Lock the gem_context->active_list while dropping the link
In reply to Chris Wilson== Series Details ==
== Series Details ==
Series: series starting with [CI,1/2] drm/i915: Lock the gem_context->active_list while dropping the link
URL : https://patchwork.freedesktop.org/series/58151/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_5770 -> Patchwork_12507
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/58151/revisions/1/mbox/
Known issues
------------
Here are the changes found in Patchwork_12507 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@amdgpu/amd_basic@query-info:
- fi-bsw-kefka: NOTRUN -> SKIP [fdo#109271] +55
* igt@gem_exec_suspend@basic-s3:
- fi-blb-e6850: PASS -> INCOMPLETE [fdo#107718]
* igt@kms_busy@basic-flip-a:
- fi-bsw-n3050: NOTRUN -> SKIP [fdo#109271] / [fdo#109278] +1
* igt@kms_busy@basic-flip-c:
- fi-bsw-kefka: NOTRUN -> SKIP [fdo#109271] / [fdo#109278]
* igt@kms_chamelium@hdmi-crc-fast:
- fi-bsw-n3050: NOTRUN -> SKIP [fdo#109271] +62
* igt@kms_pipe_crc_basic@read-crc-pipe-b:
- fi-byt-clapper: PASS -> FAIL [fdo#107362]
#### Possible fixes ####
* igt@kms_pipe_crc_basic@read-crc-pipe-a-frame-sequence:
- fi-byt-clapper: FAIL [fdo#103191] / [fdo#107362] -> PASS
#### Warnings ####
* igt@kms_chamelium@common-hpd-after-suspend:
- fi-kbl-7567u: DMESG-FAIL [fdo#105079] -> DMESG-WARN [fdo#103558] / [fdo#105079] / [fdo#105602]
* igt@prime_vgem@basic-fence-flip:
- fi-gdg-551: DMESG-FAIL [fdo#103182] -> FAIL [fdo#103182]
[fdo#103182]: https://bugs.freedesktop.org/show_bug.cgi?id=103182
[fdo#103191]: https://bugs.freedesktop.org/show_bug.cgi?id=103191
[fdo#103558]: https://bugs.freedesktop.org/show_bug.cgi?id=103558
[fdo#105079]: https://bugs.freedesktop.org/show_bug.cgi?id=105079
[fdo#105602]: https://bugs.freedesktop.org/show_bug.cgi?id=105602
[fdo#107362]: https://bugs.freedesktop.org/show_bug.cgi?id=107362
[fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
Participating hosts (44 -> 41)
------------------------------
Additional (2): fi-bsw-kefka fi-bsw-n3050
Missing (5): fi-kbl-soraka fi-hsw-4200u fi-bsw-cyan fi-icl-y fi-bdw-samus
Build changes
-------------
* Linux: CI_DRM_5770 -> Patchwork_12507
CI_DRM_5770: 7f60fa0ec6f20661a49a3eeed6e4b0a175783cf6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4888: 71ad19eb8fe4f0eecae3bf063e107293b90b9abc @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12507: b67c29ee46015f2b17f07950644d00fb276c85f3 @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
b67c29ee4601 drm/i915: Hold a reference to the active HW context 85d6793e2046 drm/i915: Lock the gem_context->active_list while dropping the link
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12507/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.IGT: success for series starting with [CI,1/2] drm/i915: Lock the gem_context->active_list while dropping the link
In reply to Chris Wilson== Series Details ==
== Series Details ==
Series: series starting with [CI,1/2] drm/i915: Lock the gem_context->active_list while dropping the link
URL : https://patchwork.freedesktop.org/series/58151/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_5770_full -> Patchwork_12507_full
====================================================
Summary
-------
**SUCCESS**
No regressions found.
Known issues
------------
Here are the changes found in Patchwork_12507_full that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@gem_ctx_param@invalid-param-get:
- shard-skl: NOTRUN -> FAIL [fdo#109559]
* igt@gem_ctx_param@invalid-param-set:
- shard-skl: NOTRUN -> FAIL [fdo#109674]
* igt@gem_softpin@noreloc-s3:
- shard-skl: PASS -> INCOMPLETE [fdo#104108] / [fdo#107773]
* igt@i915_pm_rpm@gem-evict-pwrite:
- shard-skl: NOTRUN -> INCOMPLETE [fdo#107807]
* igt@i915_pm_rpm@gem-idle:
- shard-skl: PASS -> INCOMPLETE [fdo#107807] +1
* igt@kms_busy@basic-modeset-f:
- shard-skl: NOTRUN -> SKIP [fdo#109271] / [fdo#109278] +10
* igt@kms_busy@extended-modeset-hang-newfb-render-c:
- shard-skl: NOTRUN -> DMESG-WARN [fdo#107956] +1
* igt@kms_busy@extended-pageflip-hang-newfb-render-b:
- shard-glk: PASS -> DMESG-WARN [fdo#107956]
* igt@kms_chv_cursor_fail@pipe-b-128x128-left-edge:
- shard-skl: NOTRUN -> FAIL [fdo#104671]
* igt@kms_cursor_crc@cursor-64x21-random:
- shard-apl: PASS -> FAIL [fdo#103232] +1
* igt@kms_cursor_legacy@2x-long-cursor-vs-flip-legacy:
- shard-hsw: PASS -> FAIL [fdo#105767]
* igt@kms_flip@flip-vs-expired-vblank:
- shard-skl: NOTRUN -> FAIL [fdo#105363]
* igt@kms_flip_tiling@flip-y-tiled:
- shard-skl: NOTRUN -> FAIL [fdo#108303]
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-blt:
- shard-apl: PASS -> FAIL [fdo#103167]
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-pwrite:
- shard-glk: PASS -> FAIL [fdo#103167]
* igt@kms_plane_alpha_blend@pipe-b-alpha-7efc:
- shard-skl: NOTRUN -> FAIL [fdo#107815] / [fdo#108145]
* igt@kms_plane_alpha_blend@pipe-b-coverage-7efc:
- shard-skl: NOTRUN -> FAIL [fdo#107815]
* igt@kms_rotation_crc@multiplane-rotation-cropping-bottom:
- shard-kbl: PASS -> DMESG-FAIL [fdo#105763]
* igt@kms_setmode@basic:
- shard-skl: NOTRUN -> FAIL [fdo#99912]
- shard-kbl: PASS -> FAIL [fdo#99912]
* igt@kms_vblank@pipe-c-ts-continuation-dpms-suspend:
- shard-skl: PASS -> INCOMPLETE [fdo#104108]
* igt@perf_pmu@busy-accuracy-98-vcs1:
- shard-skl: NOTRUN -> SKIP [fdo#109271] +106
* igt@sw_sync@sync_busy_fork_unixsocket:
- shard-skl: NOTRUN -> FAIL [fdo#110150 ]
* igt@tools_test@sysfs_l3_parity:
- shard-hsw: PASS -> SKIP [fdo#109271]
* igt@tools_test@tools_test:
- shard-snb: PASS -> SKIP [fdo#109271]
#### Possible fixes ####
* igt@kms_busy@extended-pageflip-hang-newfb-render-b:
- shard-apl: DMESG-WARN [fdo#107956] -> PASS
* igt@kms_ccs@pipe-a-crc-sprite-planes-basic:
- shard-glk: FAIL [fdo#108145] -> PASS
* igt@kms_cursor_crc@cursor-size-change:
- shard-apl: FAIL [fdo#103232] -> PASS
* igt@kms_draw_crc@draw-method-rgb565-mmap-cpu-ytiled:
- shard-skl: FAIL [fdo#103184] -> PASS +1
* igt@kms_draw_crc@draw-method-xrgb8888-render-untiled:
- shard-snb: SKIP [fdo#109271] -> PASS +1
* igt@kms_flip@2x-flip-vs-expired-vblank-interruptible:
- shard-glk: FAIL [fdo#105363] -> PASS +1
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-indfb-draw-mmap-wc:
- shard-skl: FAIL [fdo#105682] -> PASS
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-mmap-gtt:
- shard-apl: FAIL [fdo#103167] -> PASS
* igt@kms_frontbuffer_tracking@fbc-2p-primscrn-cur-indfb-draw-mmap-cpu:
- shard-glk: FAIL [fdo#103167] -> PASS +1
* igt@kms_frontbuffer_tracking@psr-rgb565-draw-mmap-cpu:
- shard-skl: FAIL [fdo#103167] -> PASS +1
* igt@kms_pipe_crc_basic@read-crc-pipe-a:
- shard-skl: FAIL [fdo#107362] -> PASS
* igt@kms_plane_alpha_blend@pipe-a-coverage-7efc:
- shard-skl: FAIL [fdo#107815] / [fdo#108145] -> PASS
* {igt@kms_plane_multiple@atomic-pipe-b-tiling-none}:
- shard-glk: FAIL [fdo#110037] -> PASS +1
* {igt@kms_plane_multiple@atomic-pipe-c-tiling-yf}:
- shard-apl: FAIL [fdo#110037] -> PASS +1
* igt@kms_plane_scaling@pipe-a-scaler-with-clipping-clamping:
- shard-glk: SKIP [fdo#109271] / [fdo#109278] -> PASS
* igt@kms_setmode@basic:
- shard-apl: FAIL [fdo#99912] -> PASS
* igt@kms_vblank@pipe-b-ts-continuation-dpms-suspend:
- shard-skl: INCOMPLETE [fdo#104108] / [fdo#107773] -> PASS
#### Warnings ####
* igt@kms_plane_scaling@pipe-a-scaler-with-rotation:
- shard-glk: FAIL [fdo#110098] -> SKIP [fdo#109271] / [fdo#109278]
* igt@kms_plane_scaling@pipe-b-scaler-with-rotation:
- shard-glk: SKIP [fdo#109271] / [fdo#109278] -> FAIL [fdo#110098]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103184]: https://bugs.freedesktop.org/show_bug.cgi?id=103184
[fdo#103232]: https://bugs.freedesktop.org/show_bug.cgi?id=103232
[fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
[fdo#104671]: https://bugs.freedesktop.org/show_bug.cgi?id=104671
[fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
[fdo#105682]: https://bugs.freedesktop.org/show_bug.cgi?id=105682
[fdo#105763]: https://bugs.freedesktop.org/show_bug.cgi?id=105763
[fdo#105767]: https://bugs.freedesktop.org/show_bug.cgi?id=105767
[fdo#107362]: https://bugs.freedesktop.org/show_bug.cgi?id=107362
[fdo#107773]: https://bugs.freedesktop.org/show_bug.cgi?id=107773
[fdo#107807]: https://bugs.freedesktop.org/show_bug.cgi?id=107807
[fdo#107815]: https://bugs.freedesktop.org/show_bug.cgi?id=107815
[fdo#107956]: https://bugs.freedesktop.org/show_bug.cgi?id=107956
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#108303]: https://bugs.freedesktop.org/show_bug.cgi?id=108303
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
[fdo#109559]: https://bugs.freedesktop.org/show_bug.cgi?id=109559
[fdo#109674]: https://bugs.freedesktop.org/show_bug.cgi?id=109674
[fdo#110033]: https://bugs.freedesktop.org/show_bug.cgi?id=110033
[fdo#110037]: https://bugs.freedesktop.org/show_bug.cgi?id=110037
[fdo#110038]: https://bugs.freedesktop.org/show_bug.cgi?id=110038
[fdo#110098]: https://bugs.freedesktop.org/show_bug.cgi?id=110098
[fdo#110150 ]: https://bugs.freedesktop.org/show_bug.cgi?id=110150
[fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912
Participating hosts (10 -> 9)
------------------------------
Missing (1): shard-iclb
Build changes
-------------
* Linux: CI_DRM_5770 -> Patchwork_12507
CI_DRM_5770: 7f60fa0ec6f20661a49a3eeed6e4b0a175783cf6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4888: 71ad19eb8fe4f0eecae3bf063e107293b90b9abc @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12507: b67c29ee46015f2b17f07950644d00fb276c85f3 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12507/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx