drm/i915/guc: Avoid circular locking issue on busyness flush
Subsystems (2)
PATCH 1/1 drm/i915/guc: Avoid circular locking issue on busyness flush
From: John Harrison <[email protected]>
Avoid the following lockdep complaint:
<4> [298.856498] ====================================================== <4> [298.856500] WARNING: possible circular locking dependency detected <4> [298.856503] 6.7.0-rc5-CI_DRM_14017-g58ac4ffc75b6+ #1 Tainted: G
N
<4> [298.856505] ------------------------------------------------------ <4> [298.856507] kworker/4:1H/190 is trying to acquire lock:
<4> [298.856509] ffff8881103e9978 (>->reset.backoff_srcu){++++}-{0:0}, at:_intel_gt_reset_lock+0x35/0x380 [i915]
<4> [298.856661]
but task is already holding lock:
<4> [298.856663] ffffc900013f7e58 ((work_completion)(&(&guc->timestamp.work)->work)){+.+.}-{0:0}, at:process_scheduled_works+0x264/0x530
<4> [298.856671]
which lock already depends on the new lock.
The complaint is not actually valid. The busyness worker thread does indeed hold the worker lock and then attempt to acquire the reset lock (which may have happened in reverse order elsewhere). However, it does so with a trylock that exits if the reset lock is not available (specifically to prevent this and other similar deadlocks). Unfortunately, lockdep does not understand the trylock semantics (the lock is an i915 specific custom implementation for resets).
Not doing a synchronous flush of the worker thread when a reset is in progress resolves the lockdep splat by never even attempting to grab the lock in this particular scenario.
There are situatons where a synchronous cancel is required, however. So, always do the synchronous cancel if not in reset. And add an extra synchronous cancel to the end of the reset flow to account for when a reset is occurring at driver shutdown and the cancel is no longer synchronous but could lead to unallocated memory accesses if the worker is not stopped.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 48 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +47 -1
@@ -1362,7 +1362,45 @@ static void guc_enable_busyness_worker(struct intel_guc *guc)static void guc_cancel_busyness_worker (struct intel_guc *guc) { -cancel_delayed_work_sync (&guc->timestamp.work); +/* +* There are many different call stacks that can get here. Some of them +* hold the reset mutex. The busyness worker also attempts to acquire the +* reset mutex. Synchronously flushing a worker thread requires acquiring +* the worker mutex. Lockdep sees this as a conflict. It thinks that the +* flush can deadlock because it holds the worker mutex while waiting for +* the reset mutex, but another thread is holding the reset mutex and might +* attempt to use other worker functions. +* +* In practice, this scenario does not exist because the busyness worker +* does not block waiting for the reset mutex. It does a try-lock on it and +* immediately exits if the lock is already held. Unfortunately, the mutex +* in question (I915_RESET_BACKOFF) is an i915 implementation which has lockdep +* annotation but not to the extent of explaining the 'might lock' is also a +* 'does not need to lock'. So one option would be to add more complex lockdep +* annotations to ignore the issue (if at all possible). A simpler option is to +* just not flush synchronously when a rest in progress. Given that the worker +* will just early exit and re-schedule itself anyway, there is no advantage +* to running it immediately. +* +* If a reset is not in progress, then the synchronous flush may be required. +* As noted many call stacks lead here, some during suspend and driver unload +* which do require a synchronous flush to make sure the worker is stopped +* before memory is freed. +* +* Trying to pass a 'need_sync' or 'in_reset' flag all the way down through +* every possible call stack is unfeasible. It would be too intrusive to many +* areas that really don't care about the GuC backend. However, there is the +* 'reset_in_progress' flag available, so just use that. +* +* And note that in the case of a reset occurring during driver unload +* (wedge_on_fini), skipping the cancel in _prepare (when the reset flag is set +* is fine because there is another cancel in _finish (when the reset flag is +* not). +*/ +if (guc_to_gt (guc)->uc.reset_in_progress) +cancel_delayed_work (&guc->timestamp.work); +else +cancel_delayed_work_sync (&guc->timestamp.work); }static void __reset_guc_busyness_stats (struct intel_guc *guc)
@@ -1948,8 +1986,16 @@ void intel_guc_submission_cancel_requests(struct intel_guc *guc)void intel_guc_submission_reset_finish (struct intel_guc *guc) { +/* +* Ensure the busyness worker gets cancelled even on a fatal wedge. +* Note that reset_prepare is not allowed to because it confuses lockdep. +*/ +if (guc_submission_initialized (guc)) +guc_cancel_busyness_worker (guc); +/* Reset called during driver load or during wedge? */ if (unlikely (!guc_submission_initialized (guc) || + !intel_guc_is_fw_running (guc) ||intel_gt_is_wedged (guc_to_gt (guc)))) {return ; }
drivers/gpu/drm/i915/gt/uc/intel_uc.c +1 -1
@@ -640,7 +640,7 @@ void intel_uc_reset_finish(struct intel_uc *uc) uc->reset_in_progress = false;/* Firmware expected to be running when this function is called */ -if (intel_guc_is_fw_running (guc) &&intel_uc_uses_guc_submission (uc)) +if (intel_uc_uses_guc_submission (uc))intel_guc_submission_reset_finish (guc); }
Signature · 1 line
2.41.0
Hi John,
Quoted 38 lines · On Tue, Dec 19, 2023 at 11:59:57AM -0800, [email protected] wrote:
From: John Harrison <[email protected]>
Avoid the following lockdep complaint:
<4> [298.856498] ====================================================== <4> [298.856500] WARNING: possible circular locking dependency detected <4> [298.856503] 6.7.0-rc5-CI_DRM_14017-g58ac4ffc75b6+ #1 Tainted: G
N
<4> [298.856505] ------------------------------------------------------ <4> [298.856507] kworker/4:1H/190 is trying to acquire lock:
<4> [298.856509]ffff8881103e9978(>->reset.backoff_srcu){++++}-{0:0}, at:_intel_gt_reset_lock+0x35/0x380[i915]
<4> [298.856661]
but task is already holding lock:
<4> [298.856663]ffffc900013f7e58((work_completion)(&(&guc->timestamp.work)->work)){+.+.}-{0:0}, at:process_scheduled_works+0x264/0x530
<4> [298.856671]
which lock already depends on the new lock.The complaint is not actually valid. The busyness worker thread does indeed hold the worker lock and then attempt to acquire the reset lock (which may have happened in reverse order elsewhere). However, it does so with a trylock that exits if the reset lock is not available (specifically to prevent this and other similar deadlocks). Unfortunately, lockdep does not understand the trylock semantics (the lock is an i915 specific custom implementation for resets).
Not doing a synchronous flush of the worker thread when a reset is in progress resolves the lockdep splat by never even attempting to grab the lock in this particular scenario.
There are situatons where a synchronous cancel is required, however. So, always do the synchronous cancel if not in reset. And add an extra synchronous cancel to the end of the reset flow to account for when a reset is occurring at driver shutdown and the cancel is no longer synchronous but could lead to unallocated memory accesses if the worker is not stopped.
Quoted 4 lines
Signed-off-by Zhanjun Dong <[email protected]>Signed-off-by John Harrison <[email protected]>Cc Andi Shyti <[email protected]>Cc Daniel Vetter <[email protected]>
Thanks,
Andi
Patchwork
CI✗ Fi.CI.CHECKPATCH: warning for drm/i915/guc: Avoid circular locking issue on busyness flush (rev6)
In reply to [email protected]== Series Details ==
== Series Details ==
Series: drm/i915/guc: Avoid circular locking issue on busyness flush (rev6)
URL : https://patchwork.freedesktop.org/series/127985/
State : warning
== Summary ==
Error: dim checkpatch failedd0cacf327d6c drm/i915/guc: Avoid circular locking issue on busyness flush
-:13: WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #13:
<4> [298.856509] ffff8881103e9978 (>->reset.backoff_srcu){++++}-{0:0}, at:
total: 0 errors, 1 warnings, 0 checks, 70 lines checked
Patchwork
CI✗ Fi.CI.BAT: failure for drm/i915/guc: Avoid circular locking issue on busyness flush (rev6)
In reply to [email protected]== Series Details ==
== Series Details ==
Series: drm/i915/guc: Avoid circular locking issue on busyness flush (rev6)
URL : https://patchwork.freedesktop.org/series/127985/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_14077 -> Patchwork_127985v6
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_127985v6 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes
introduced in Patchwork_127985v6, please notify your bug team ([email protected]) 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_127985v6/index.html
Participating hosts (38 -> 37)
------------------------------
Additional (2): fi-bsw-nick fi-pnv-d510
Missing (3): bat-kbl-2 bat-dg2-9 fi-snb-2520m
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_127985v6:
### IGT changes ###
#### Possible regressions ####
* igt@i915_selftest@live@gt_pm:
- bat-rpls-2: NOTRUN -> [DMESG-FAIL][1]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-2/igt@i915_selftest@live@gt_pm.html
- bat-adln-1: NOTRUN -> [DMESG-FAIL][2]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adln-1/igt@i915_selftest@live@gt_pm.html
* igt@i915_suspend@basic-s3-without-i915:
- bat-adlp-6: NOTRUN -> [INCOMPLETE][3]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adlp-6/igt@[email protected]
Known issues
------------
Here are the changes found in Patchwork_127985v6 that come from known issues:
### CI changes ###
#### Possible fixes ####
* boot:
- bat-jsl-1: [FAIL][4] ([i915#8293]) -> [PASS][5]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-jsl-1/boot.html
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/boot.html
### IGT changes ###
#### Issues hit ####
* igt@debugfs_test@basic-hwmon:
- bat-jsl-1: NOTRUN -> [SKIP][6] ([i915#9318])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
* igt@gem_huc_copy@huc-copy:
- bat-jsl-1: NOTRUN -> [SKIP][7] ([i915#2190])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
* igt@gem_lmem_swapping@basic:
- fi-pnv-d510: NOTRUN -> [SKIP][8] ([fdo#109271]) +28 other tests skip
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/fi-pnv-d510/igt@[email protected]
- bat-adln-1: NOTRUN -> [SKIP][9] ([i915#4613]) +3 other tests skip
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adln-1/igt@[email protected]
* igt@gem_lmem_swapping@parallel-random-engines:
- fi-bsw-nick: NOTRUN -> [SKIP][10] ([fdo#109271]) +15 other tests skip
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/fi-bsw-nick/igt@[email protected]
- bat-rplp-1: NOTRUN -> [SKIP][11] ([i915#4613]) +3 other tests skip
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rplp-1/igt@[email protected]
* igt@gem_lmem_swapping@random-engines:
- bat-adlp-6: NOTRUN -> [SKIP][12] ([i915#4613]) +3 other tests skip
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adlp-6/igt@[email protected]
* igt@gem_lmem_swapping@verify-random:
- bat-rpls-2: NOTRUN -> [SKIP][13] ([i915#4613]) +3 other tests skip
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-2/igt@[email protected]
- bat-jsl-1: NOTRUN -> [SKIP][14] ([i915#4613]) +3 other tests skip
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
* igt@i915_pm_rps@basic-api:
- bat-rpls-2: NOTRUN -> [SKIP][15] ([i915#6621])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-2/igt@[email protected]
- bat-adlp-6: NOTRUN -> [SKIP][16] ([i915#6621])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adlp-6/igt@[email protected]
- bat-rplp-1: NOTRUN -> [SKIP][17] ([i915#6621])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rplp-1/igt@[email protected]
- bat-adln-1: NOTRUN -> [SKIP][18] ([i915#6621])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adln-1/igt@[email protected]
* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy:
- bat-jsl-1: NOTRUN -> [SKIP][19] ([i915#4103]) +1 other test skip
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
* igt@kms_dsc@dsc-basic:
- bat-jsl-1: NOTRUN -> [SKIP][20] ([i915#3555] / [i915#9886])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
* igt@kms_force_connector_basic@force-load-detect:
- bat-jsl-1: NOTRUN -> [SKIP][21] ([fdo#109285])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
* igt@kms_setmode@basic-clone-single-crtc:
- bat-adlp-6: NOTRUN -> [SKIP][22] ([i915#3555])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adlp-6/igt@[email protected]
- bat-rplp-1: NOTRUN -> [SKIP][23] ([i915#3555])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rplp-1/igt@[email protected]
- bat-adln-1: NOTRUN -> [SKIP][24] ([i915#3555])
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adln-1/igt@[email protected]
- bat-jsl-1: NOTRUN -> [SKIP][25] ([i915#3555])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-jsl-1/igt@[email protected]
- bat-rpls-2: NOTRUN -> [SKIP][26] ([i915#3555])
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-2/igt@[email protected]
* igt@prime_vgem@basic-fence-read:
- bat-rpls-2: NOTRUN -> [SKIP][27] ([fdo#109295] / [i915#3708]) +2 other tests skip
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-2/igt@[email protected]
- bat-adlp-6: NOTRUN -> [SKIP][28] ([fdo#109295] / [i915#3291] / [i915#3708]) +2 other tests skip
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adlp-6/igt@[email protected]
* igt@prime_vgem@basic-read:
- bat-rplp-1: NOTRUN -> [SKIP][29] ([i915#3708]) +2 other tests skip
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rplp-1/igt@[email protected]
* igt@prime_vgem@basic-write:
- bat-adln-1: NOTRUN -> [SKIP][30] ([fdo#109295] / [i915#3291]) +2 other tests skip
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adln-1/igt@[email protected]
#### Possible fixes ####
* igt@i915_selftest@live@workarounds:
- bat-dg2-11: [DMESG-FAIL][31] ([i915#9500]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-dg2-11/igt@i915_selftest@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-dg2-11/igt@i915_selftest@[email protected]
* igt@kms_frontbuffer_tracking@basic:
- {bat-rpls-3}: [SKIP][33] ([i915#1849] / [i915#5354]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-rpls-3/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-3/igt@[email protected]
* igt@kms_pm_backlight@basic-brightness@edp-1:
- bat-adlp-6: [ABORT][35] ([i915#8668]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-adlp-6/igt@kms_pm_backlight@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adlp-6/igt@kms_pm_backlight@[email protected]
- bat-rplp-1: [ABORT][37] ([i915#8668]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-rplp-1/igt@kms_pm_backlight@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rplp-1/igt@kms_pm_backlight@[email protected]
* igt@kms_pm_rpm@basic-pci-d3-state:
- bat-adln-1: [ABORT][39] ([i915#8668]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-adln-1/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-adln-1/igt@[email protected]
* igt@kms_pm_rpm@basic-rte:
- bat-rpls-2: [ABORT][41] ([i915#8668] / [i915#9368] / [i915#9897]) -> [PASS][42]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_14077/bat-rpls-2/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/bat-rpls-2/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#109295]: https://bugs.freedesktop.org/show_bug.cgi?id=109295
[i915#1849]: https://gitlab.freedesktop.org/drm/intel/issues/1849
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#3291]: https://gitlab.freedesktop.org/drm/intel/issues/3291
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#5354]: https://gitlab.freedesktop.org/drm/intel/issues/5354
[i915#6621]: https://gitlab.freedesktop.org/drm/intel/issues/6621
[i915#8293]: https://gitlab.freedesktop.org/drm/intel/issues/8293
[i915#8668]: https://gitlab.freedesktop.org/drm/intel/issues/8668
[i915#9318]: https://gitlab.freedesktop.org/drm/intel/issues/9318
[i915#9368]: https://gitlab.freedesktop.org/drm/intel/issues/9368
[i915#9500]: https://gitlab.freedesktop.org/drm/intel/issues/9500
[i915#9673]: https://gitlab.freedesktop.org/drm/intel/issues/9673
[i915#9732]: https://gitlab.freedesktop.org/drm/intel/issues/9732
[i915#9886]: https://gitlab.freedesktop.org/drm/intel/issues/9886
[i915#9897]: https://gitlab.freedesktop.org/drm/intel/issues/9897
Build changes
-------------
* Linux: CI_DRM_14077 -> Patchwork_127985v6
CI-20190529: 20190529
CI_DRM_14077: f23ccca46969b7c4a5d6633724c46065ae2bfd97 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7655: ddf7cf40a00caa7d02f3729e1e50f78f102463d9 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_127985v6: f23ccca46969b7c4a5d6633724c46065ae2bfd97 @ git://anongit.freedesktop.org/gfx-ci/linux
### Linux commits
19ded9d6c388 drm/i915/guc: Avoid circular locking issue on busyness flush
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_127985v6/index.html
Quoted 85 lines · On Tue, Dec 19, 2023 at 11:59:57AM -0800, [email protected] wrote:
From: John Harrison <[email protected]>
Avoid the following lockdep complaint:
<4> [298.856498] ====================================================== <4> [298.856500] WARNING: possible circular locking dependency detected <4> [298.856503] 6.7.0-rc5-CI_DRM_14017-g58ac4ffc75b6+ #1 Tainted: G
N
<4> [298.856505] ------------------------------------------------------ <4> [298.856507] kworker/4:1H/190 is trying to acquire lock:
<4> [298.856509]ffff8881103e9978(>->reset.backoff_srcu){++++}-{0:0}, at:_intel_gt_reset_lock+0x35/0x380[i915]
<4> [298.856661]
but task is already holding lock:
<4> [298.856663]ffffc900013f7e58((work_completion)(&(&guc->timestamp.work)->work)){+.+.}-{0:0}, at:process_scheduled_works+0x264/0x530
<4> [298.856671]
which lock already depends on the new lock.The complaint is not actually valid. The busyness worker thread does indeed hold the worker lock and then attempt to acquire the reset lock (which may have happened in reverse order elsewhere). However, it does so with a trylock that exits if the reset lock is not available (specifically to prevent this and other similar deadlocks). Unfortunately, lockdep does not understand the trylock semantics (the lock is an i915 specific custom implementation for resets).
Not doing a synchronous flush of the worker thread when a reset is in progress resolves the lockdep splat by never even attempting to grab the lock in this particular scenario.
There are situatons where a synchronous cancel is required, however. So, always do the synchronous cancel if not in reset. And add an extra synchronous cancel to the end of the reset flow to account for when a reset is occurring at driver shutdown and the cancel is no longer synchronous but could lead to unallocated memory accesses if the worker is not stopped.
Signed-off-by Zhanjun Dong <[email protected]>Signed-off-by John Harrison <[email protected]>Cc Andi Shyti <[email protected]>Cc Daniel Vetter <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 48 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +29
-1@@ -1362,7 +1362,45 @@ static void guc_enable_busyness_worker(struct intel_guc *guc)static void guc_cancel_busyness_worker (struct intel_guc *guc) { -cancel_delayed_work_sync (&guc->timestamp.work); +/* +* There are many different call stacks that can get here. Some of them +* hold the reset mutex. The busyness worker also attempts to acquire the +* reset mutex. Synchronously flushing a worker thread requires acquiring +* the worker mutex. Lockdep sees this as a conflict. It thinks that the +* flush can deadlock because it holds the worker mutex while waiting for +* the reset mutex, but another thread is holding the reset mutex and might +* attempt to use other worker functions. +* +* In practice, this scenario does not exist because the busyness worker +* does not block waiting for the reset mutex. It does a try-lock on it and +* immediately exits if the lock is already held. Unfortunately, the mutex +* in question (I915_RESET_BACKOFF) is an i915 implementation which has lockdep +* annotation but not to the extent of explaining the 'might lock' is also a +* 'does not need to lock'. So one option would be to add more complex lockdep +* annotations to ignore the issue (if at all possible). A simpler option is to +* just not flush synchronously when a rest in progress. Given that the worker +* will just early exit and re-schedule itself anyway, there is no advantage +* to running it immediately. +* +* If a reset is not in progress, then the synchronous flush may be required. +* As noted many call stacks lead here, some during suspend and driver unload +* which do require a synchronous flush to make sure the worker is stopped +* before memory is freed. +* +* Trying to pass a 'need_sync' or 'in_reset' flag all the way down through +* every possible call stack is unfeasible. It would be too intrusive to many +* areas that really don't care about the GuC backend. However, there is the +* 'reset_in_progress' flag available, so just use that.
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_enable_busyness_worker(struct intel_guc *guc) · line 1403
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+* +* And note that in the case of a reset occurring during driver unload +* (wedge_on_fini), skipping the cancel in _prepare (when the reset flag is set +* is fine because there is another cancel in _finish (when the reset flag is +* not). +*/ +if (guc_to_gt (guc)->uc.reset_in_progress) +cancel_delayed_work (&guc->timestamp.work); +else +cancel_delayed_work_sync (&guc->timestamp.work);
I think it's all fairly horrible (but that's not news), but this comment here I think explains in adequate detail what's all going on, what all matters, why it's all safe and why it's rather hard to fix in a clean fashion. So realistically about as good as it will ever get.
More importantly, it doesn't gloss over any of the details which do matter (of which there is a lot, as the length of this comment shows).
Quoted 36 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8
-0}static void __reset_guc_busyness_stats (struct intel_guc *guc)@@ -1948,8 +1986,16 @@ void intel_guc_submission_cancel_requests(struct intel_guc *guc)void intel_guc_submission_reset_finish (struct intel_guc *guc) { +/* +* Ensure the busyness worker gets cancelled even on a fatal wedge. +* Note that reset_prepare is not allowed to because it confuses lockdep. +*/ +if (guc_submission_initialized (guc)) +guc_cancel_busyness_worker (guc); +/* Reset called during driver load or during wedge? */ if (unlikely (!guc_submission_initialized (guc) || + !intel_guc_is_fw_running (guc) ||intel_gt_is_wedged (guc_to_gt (guc)))) {return ; }drivers/gpu/drm/i915/gt/uc/intel_uc.c +1
-1@@ -640,7 +640,7 @@ void intel_uc_reset_finish(struct intel_uc *uc) uc->reset_in_progress = false;/* Firmware expected to be running when this function is called */ -if (intel_guc_is_fw_running (guc) &&intel_uc_uses_guc_submission (uc)) +if (intel_uc_uses_guc_submission (uc))intel_guc_submission_reset_finish (guc); }Signature · 1 line
2.41.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch