diff mbox series

Revert "Revert "drm/i915: Hold reference to intel_context over life of i915_request""

Message ID 20230719145317.1485514-1-andrzej.hajda@intel.com (mailing list archive)
State New, archived
Headers show
Series Revert "Revert "drm/i915: Hold reference to intel_context over life of i915_request"" | expand

Commit Message

Andrzej Hajda July 19, 2023, 2:53 p.m. UTC
This reverts commit bcb9aa45d5a0e11ef91245330c53cde214d15e8d.

The problem with this patch is that it makes rq->engine dangling pointer
after context removal. At least two places were located where it ends
with errors:
- i915_fence_release: intel_engine_is_virtual(rq->engine),
- i915_request_wait_timeout: mutex_(acquire|release)(&rq->engine->gt...)
It is possible there are more such places.
Taking context reference prevents this behaviour.

Commit message suggested the patch prevented reference loop in VM_BIND,
but since VM_BIND was dropped the revert hopefuly should be safe.

The patch fixes bug detected by KASAN with following signature:
i915 0000:00:02.0: [drm:i915_drop_caches_set [i915]] Dropping caches: 0x0000005c [0x0000005c]
BUG: KASAN: slab-use-after-free in i915_fence_release+0x2a2/0x2f0 [i915]
Read of size 4 at addr ffff88813ffda6e8 by task kworker/u32:10/157
...
Allocated by task 1184:
...
guc_create_virtual+0x4d/0x1160 [i915]
i915_gem_create_context+0x11ee/0x18c0 [i915]
...
Freed by task 151:
...
intel_guc_deregister_done_process_msg+0x324/0x6d0 [i915]
...

Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/7926
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
---
Hi Niranjana, Matt,

Could you look at this revert, to verify if situation described in
reverted patch will not happen now, without VM_BIND.

Regards
Andrzej
---
 drivers/gpu/drm/i915/i915_request.c | 52 +++++++++++------------------
 1 file changed, 20 insertions(+), 32 deletions(-)

Comments

Andrzej Hajda July 20, 2023, 11:54 a.m. UTC | #1
On 19.07.2023 20:58, Patchwork wrote:
> Project List - Patchwork *Patch Details*
> *Series:* 	Revert "Revert "drm/i915: Hold reference to intel_context 
> over life of i915_request""
> *URL:* 	https://patchwork.freedesktop.org/series/120990/
> *State:* 	failure
> *Details:* 
> https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/index.html
>
>
>   CI Bug Log - changes from CI_DRM_13396 -> Patchwork_120990v1
>
>
>     Summary
>
> *FAILURE*
>
> Serious unknown changes coming with Patchwork_120990v1 absolutely need 
> to be
> verified manually.
>
> If you think the reported changes have nothing to do with the changes
> introduced in Patchwork_120990v1, please notify your bug team to allow 
> them
> to document this new failure mode, which will reduce false positives 
> in CI.
>
> External URL: 
> https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/index.html
>
>
>     Participating hosts (42 -> 43)
>
> Additional (2): fi-kbl-soraka bat-rpls-2
> Missing (1): fi-snb-2520m
>
>
>     Possible new issues
>
> Here are the unknown changes that may have been introduced in 
> Patchwork_120990v1:
>
>
>       IGT changes
>
>
>         Possible regressions
>
>  *
>
>     igt@debugfs_test@read_all_entries:
>
>       o bat-mtlp-6: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-mtlp-6/igt@debugfs_test@read_all_entries.html>
>         -> DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-mtlp-6/igt@debugfs_test@read_all_entries.html>
>

Known bug: https://gitlab.freedesktop.org/drm/intel/-/issues/8940

>  *
>  *
>
>     igt@i915_selftest@live@gt_mocs:
>
>       o bat-adlp-9: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-adlp-9/igt@i915_selftest@live@gt_mocs.html>
>         -> DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-adlp-9/igt@i915_selftest@live@gt_mocs.html>
>

Occasional bug: https://gitlab.freedesktop.org/drm/intel/-/issues/5830

Does not seems to be related.

Regards
Andrzej

>  *
>
>
>         Warnings
>
>   * igt@i915_selftest@live@slpc:
>       o bat-mtlp-6: DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-mtlp-6/igt@i915_selftest@live@slpc.html>
>         (i915#6367
>         <https://gitlab.freedesktop.org/drm/intel/issues/6367>) ->
>         DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-mtlp-6/igt@i915_selftest@live@slpc.html>
>
>
>     Known issues
>
> Here are the changes found in Patchwork_120990v1 that come from known 
> issues:
>
>
>       IGT changes
>
>
>         Issues hit
>
>  *
>
>     igt@debugfs_test@basic-hwmon:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@debugfs_test@basic-hwmon.html>
>         (i915#7456 <https://gitlab.freedesktop.org/drm/intel/issues/7456>)
>  *
>
>     igt@fbdev@info:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@fbdev@info.html>
>         (i915#1849
>         <https://gitlab.freedesktop.org/drm/intel/issues/1849> /
>         i915#2582 <https://gitlab.freedesktop.org/drm/intel/issues/2582>)
>  *
>
>     igt@fbdev@read:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@fbdev@read.html>
>         (i915#2582
>         <https://gitlab.freedesktop.org/drm/intel/issues/2582>) +3
>         similar issues
>  *
>
>     igt@gem_huc_copy@huc-copy:
>
>       o fi-kbl-soraka: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-kbl-soraka/igt@gem_huc_copy@huc-copy.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271> /
>         i915#2190 <https://gitlab.freedesktop.org/drm/intel/issues/2190>)
>  *
>
>     igt@gem_lmem_swapping@basic:
>
>       o fi-kbl-soraka: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-kbl-soraka/igt@gem_lmem_swapping@basic.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271> /
>         i915#4613
>         <https://gitlab.freedesktop.org/drm/intel/issues/4613>) +3
>         similar issues
>  *
>
>     igt@gem_lmem_swapping@verify-random:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@gem_lmem_swapping@verify-random.html>
>         (i915#4613
>         <https://gitlab.freedesktop.org/drm/intel/issues/4613>) +3
>         similar issues
>  *
>
>     igt@gem_tiled_pread_basic:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@gem_tiled_pread_basic.html>
>         (i915#3282 <https://gitlab.freedesktop.org/drm/intel/issues/3282>)
>  *
>
>     igt@i915_pm_backlight@basic-brightness:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@i915_pm_backlight@basic-brightness.html>
>         (i915#7561 <https://gitlab.freedesktop.org/drm/intel/issues/7561>)
>  *
>
>     igt@i915_pm_rpm@basic-rte:
>
>       o fi-cfl-8109u: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/fi-cfl-8109u/igt@i915_pm_rpm@basic-rte.html>
>         -> FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-cfl-8109u/igt@i915_pm_rpm@basic-rte.html>
>         (i915#7940 <https://gitlab.freedesktop.org/drm/intel/issues/7940>)
>  *
>
>     igt@i915_pm_rps@basic-api:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@i915_pm_rps@basic-api.html>
>         (i915#6621 <https://gitlab.freedesktop.org/drm/intel/issues/6621>)
>  *
>
>     igt@i915_selftest@live@gt_pm:
>
>      o
>
>         bat-rpls-2: NOTRUN -> DMESG-FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@i915_selftest@live@gt_pm.html>
>         (i915#4258
>         <https://gitlab.freedesktop.org/drm/intel/issues/4258> /
>         i915#7913 <https://gitlab.freedesktop.org/drm/intel/issues/7913>)
>
>      o
>
>         fi-kbl-soraka: NOTRUN -> DMESG-FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-kbl-soraka/igt@i915_selftest@live@gt_pm.html>
>         (i915#1886
>         <https://gitlab.freedesktop.org/drm/intel/issues/1886> /
>         i915#7913 <https://gitlab.freedesktop.org/drm/intel/issues/7913>)
>
>  *
>
>     igt@i915_selftest@live@migrate:
>
>      o
>
>         bat-rpls-2: NOTRUN -> DMESG-FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@i915_selftest@live@migrate.html>
>         (i915#7699
>         <https://gitlab.freedesktop.org/drm/intel/issues/7699> /
>         i915#7913 <https://gitlab.freedesktop.org/drm/intel/issues/7913>)
>
>      o
>
>         bat-dg2-11: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-dg2-11/igt@i915_selftest@live@migrate.html>
>         -> DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-dg2-11/igt@i915_selftest@live@migrate.html>
>         (i915#7699 <https://gitlab.freedesktop.org/drm/intel/issues/7699>)
>
>  *
>
>     igt@i915_selftest@live@mman:
>
>       o bat-rpls-2: NOTRUN -> TIMEOUT
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@i915_selftest@live@mman.html>
>         (i915#6794
>         <https://gitlab.freedesktop.org/drm/intel/issues/6794> /
>         i915#7392 <https://gitlab.freedesktop.org/drm/intel/issues/7392>)
>  *
>
>     igt@i915_selftest@live@requests:
>
>       o bat-mtlp-8: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-mtlp-8/igt@i915_selftest@live@requests.html>
>         -> DMESG-FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-mtlp-8/igt@i915_selftest@live@requests.html>
>         (i915#8497 <https://gitlab.freedesktop.org/drm/intel/issues/8497>)
>  *
>
>     igt@i915_selftest@live@slpc:
>
>       o bat-mtlp-8: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-mtlp-8/igt@i915_selftest@live@slpc.html>
>         -> DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-mtlp-8/igt@i915_selftest@live@slpc.html>
>         (i915#6367 <https://gitlab.freedesktop.org/drm/intel/issues/6367>)
>  *
>
>     igt@i915_suspend@basic-s2idle-without-i915:
>
>       o bat-rpls-2: NOTRUN -> WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@i915_suspend@basic-s2idle-without-i915.html>
>         (i915#8747 <https://gitlab.freedesktop.org/drm/intel/issues/8747>)
>  *
>
>     igt@kms_busy@basic:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_busy@basic.html>
>         (i915#1845
>         <https://gitlab.freedesktop.org/drm/intel/issues/1845>) +15
>         similar issues
>  *
>
>     igt@kms_chamelium_edid@hdmi-edid-read:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_chamelium_edid@hdmi-edid-read.html>
>         (i915#7828
>         <https://gitlab.freedesktop.org/drm/intel/issues/7828>) +8
>         similar issues
>  *
>
>     igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
>
>       o fi-kbl-soraka: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-kbl-soraka/igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271>) +15
>         similar issues
>  *
>
>     igt@kms_flip@basic-flip-vs-dpms:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_flip@basic-flip-vs-dpms.html>
>         (i915#3637
>         <https://gitlab.freedesktop.org/drm/intel/issues/3637>) +3
>         similar issues
>  *
>
>     igt@kms_force_connector_basic@force-load-detect:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_force_connector_basic@force-load-detect.html>
>         (fdo#109285 <https://bugs.freedesktop.org/show_bug.cgi?id=109285>)
>  *
>
>     igt@kms_frontbuffer_tracking@basic:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_frontbuffer_tracking@basic.html>
>         (i915#1849 <https://gitlab.freedesktop.org/drm/intel/issues/1849>)
>  *
>
>     igt@kms_psr@primary_mmap_gtt:
>
>       o bat-rplp-1: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rplp-1/igt@kms_psr@primary_mmap_gtt.html>
>         (i915#1072 <https://gitlab.freedesktop.org/drm/intel/issues/1072>)
>  *
>
>     igt@kms_psr@sprite_plane_onoff:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_psr@sprite_plane_onoff.html>
>         (i915#1072
>         <https://gitlab.freedesktop.org/drm/intel/issues/1072>) +3
>         similar issues
>  *
>
>     igt@kms_setmode@basic-clone-single-crtc:
>
>      o
>
>         bat-rplp-1: NOTRUN -> ABORT
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rplp-1/igt@kms_setmode@basic-clone-single-crtc.html>
>         (i915#8260
>         <https://gitlab.freedesktop.org/drm/intel/issues/8260> /
>         i915#8668 <https://gitlab.freedesktop.org/drm/intel/issues/8668>)
>
>      o
>
>         bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@kms_setmode@basic-clone-single-crtc.html>
>         (i915#3555 <https://gitlab.freedesktop.org/drm/intel/issues/3555>)
>
>  *
>
>     igt@prime_vgem@basic-fence-flip:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@prime_vgem@basic-fence-flip.html>
>         (fdo#109295
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109295> /
>         i915#1845
>         <https://gitlab.freedesktop.org/drm/intel/issues/1845> /
>         i915#3708 <https://gitlab.freedesktop.org/drm/intel/issues/3708>)
>  *
>
>     igt@prime_vgem@basic-write:
>
>       o bat-rpls-2: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-2/igt@prime_vgem@basic-write.html>
>         (fdo#109295
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109295> /
>         i915#3708
>         <https://gitlab.freedesktop.org/drm/intel/issues/3708>) +2
>         similar issues
>
>
>         Possible fixes
>
>  *
>
>     igt@core_auth@basic-auth:
>
>       o bat-mtlp-6: DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-mtlp-6/igt@core_auth@basic-auth.html>
>         -> PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-mtlp-6/igt@core_auth@basic-auth.html>
>  *
>
>     igt@i915_pm_rpm@basic-rte:
>
>       o fi-tgl-1115g4: FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/fi-tgl-1115g4/igt@i915_pm_rpm@basic-rte.html>
>         (i915#7940
>         <https://gitlab.freedesktop.org/drm/intel/issues/7940>) ->
>         PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-tgl-1115g4/igt@i915_pm_rpm@basic-rte.html>
>  *
>
>     igt@i915_selftest@live@gt_heartbeat:
>
>       o fi-glk-j4005: DMESG-FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/fi-glk-j4005/igt@i915_selftest@live@gt_heartbeat.html>
>         (i915#5334
>         <https://gitlab.freedesktop.org/drm/intel/issues/5334>) ->
>         PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-glk-j4005/igt@i915_selftest@live@gt_heartbeat.html>
>  *
>
>     igt@i915_selftest@live@guc:
>
>       o bat-rpls-1: DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-rpls-1/igt@i915_selftest@live@guc.html>
>         (i915#7852
>         <https://gitlab.freedesktop.org/drm/intel/issues/7852>) ->
>         PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rpls-1/igt@i915_selftest@live@guc.html>
>
>
>         Warnings
>
>  *
>
>     igt@i915_module_load@load:
>
>       o bat-adlp-11: DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-adlp-11/igt@i915_module_load@load.html>
>         (i915#4423
>         <https://gitlab.freedesktop.org/drm/intel/issues/4423>) ->
>         ABORT
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-adlp-11/igt@i915_module_load@load.html>
>         (i915#4423 <https://gitlab.freedesktop.org/drm/intel/issues/4423>)
>  *
>
>     igt@i915_pm_rpm@basic-pci-d3-state:
>
>       o fi-cfl-guc: FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/fi-cfl-guc/igt@i915_pm_rpm@basic-pci-d3-state.html>
>         (i915#7691
>         <https://gitlab.freedesktop.org/drm/intel/issues/7691>) ->
>         FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/fi-cfl-guc/igt@i915_pm_rpm@basic-pci-d3-state.html>
>         (i915#7940 <https://gitlab.freedesktop.org/drm/intel/issues/7940>)
>  *
>
>     igt@kms_psr@sprite_plane_onoff:
>
>       o bat-rplp-1: ABORT
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13396/bat-rplp-1/igt@kms_psr@sprite_plane_onoff.html>
>         (i915#8442
>         <https://gitlab.freedesktop.org/drm/intel/issues/8442> /
>         i915#8668
>         <https://gitlab.freedesktop.org/drm/intel/issues/8668> /
>         i915#8712
>         <https://gitlab.freedesktop.org/drm/intel/issues/8712>) ->
>         SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_120990v1/bat-rplp-1/igt@kms_psr@sprite_plane_onoff.html>
>         (i915#1072 <https://gitlab.freedesktop.org/drm/intel/issues/1072>)
>
> {name}: This element is suppressed. This means it is ignored when 
> computing
> the status of the difference (SUCCESS, WARNING, or FAILURE).
>
>
>     Build changes
>
>   * Linux: CI_DRM_13396 -> Patchwork_120990v1
>
> CI-20190529: 20190529
> CI_DRM_13396: da1bb773ff84001b185e7bec54b32b89dff44f91 @ 
> git://anongit.freedesktop.org/gfx-ci/linux
> IGT_7394: 3b0c82d7e9f1b8708d351243de7f227153793ede @ 
> https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
> Patchwork_120990v1: da1bb773ff84001b185e7bec54b32b89dff44f91 @ 
> git://anongit.freedesktop.org/gfx-ci/linux
>
>
>       Linux commits
>
> cf364789fcd3 Revert "Revert "drm/i915: Hold reference to intel_context 
> over life of i915_request""
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
index 894068bb37b6f1..c5fe199b046d01 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -134,42 +134,17 @@  static void i915_fence_release(struct dma_fence *fence)
 	i915_sw_fence_fini(&rq->semaphore);
 
 	/*
-	 * Keep one request on each engine for reserved use under mempressure
+	 * Keep one request on each engine for reserved use under mempressure,
 	 * do not use with virtual engines as this really is only needed for
 	 * kernel contexts.
-	 *
-	 * We do not hold a reference to the engine here and so have to be
-	 * very careful in what rq->engine we poke. The virtual engine is
-	 * referenced via the rq->context and we released that ref during
-	 * i915_request_retire(), ergo we must not dereference a virtual
-	 * engine here. Not that we would want to, as the only consumer of
-	 * the reserved engine->request_pool is the power management parking,
-	 * which must-not-fail, and that is only run on the physical engines.
-	 *
-	 * Since the request must have been executed to be have completed,
-	 * we know that it will have been processed by the HW and will
-	 * not be unsubmitted again, so rq->engine and rq->execution_mask
-	 * at this point is stable. rq->execution_mask will be a single
-	 * bit if the last and _only_ engine it could execution on was a
-	 * physical engine, if it's multiple bits then it started on and
-	 * could still be on a virtual engine. Thus if the mask is not a
-	 * power-of-two we assume that rq->engine may still be a virtual
-	 * engine and so a dangling invalid pointer that we cannot dereference
-	 *
-	 * For example, consider the flow of a bonded request through a virtual
-	 * engine. The request is created with a wide engine mask (all engines
-	 * that we might execute on). On processing the bond, the request mask
-	 * is reduced to one or more engines. If the request is subsequently
-	 * bound to a single engine, it will then be constrained to only
-	 * execute on that engine and never returned to the virtual engine
-	 * after timeslicing away, see __unwind_incomplete_requests(). Thus we
-	 * know that if the rq->execution_mask is a single bit, rq->engine
-	 * can be a physical engine with the exact corresponding mask.
 	 */
 	if (!intel_engine_is_virtual(rq->engine) &&
-	    is_power_of_2(rq->execution_mask) &&
-	    !cmpxchg(&rq->engine->request_pool, NULL, rq))
+	    !cmpxchg(&rq->engine->request_pool, NULL, rq)) {
+		intel_context_put(rq->context);
 		return;
+	}
+
+	intel_context_put(rq->context);
 
 	kmem_cache_free(slab_requests, rq);
 }
@@ -946,7 +921,19 @@  __i915_request_create(struct intel_context *ce, gfp_t gfp)
 		}
 	}
 
-	rq->context = ce;
+	/*
+	 * Hold a reference to the intel_context over life of an i915_request.
+	 * Without this an i915_request can exist after the context has been
+	 * destroyed (e.g. request retired, context closed, but user space holds
+	 * a reference to the request from an out fence). In the case of GuC
+	 * submission + virtual engine, the engine that the request references
+	 * is also destroyed which can trigger bad pointer dref in fence ops
+	 * (e.g. i915_fence_get_driver_name). We could likely change these
+	 * functions to avoid touching the engine but let's just be safe and
+	 * hold the intel_context reference. In execlist mode the request always
+	 * eventually points to a physical engine so this isn't an issue.
+	 */
+	rq->context = intel_context_get(ce);
 	rq->engine = ce->engine;
 	rq->ring = ce->ring;
 	rq->execution_mask = ce->engine->mask;
@@ -1022,6 +1009,7 @@  __i915_request_create(struct intel_context *ce, gfp_t gfp)
 	GEM_BUG_ON(!list_empty(&rq->sched.waiters_list));
 
 err_free:
+	intel_context_put(ce);
 	kmem_cache_free(slab_requests, rq);
 err_unreserve:
 	intel_context_unpin(ce);