Skip to content

drm/asahi: g17: hold one compute cell lock while choosing a channel - #4039

Open
DjDeveloperr wants to merge 1 commit into
mainfrom
fix/g17-one-compute-cell-lock
Open

DjDeveloperr wants to merge 1 commit into
mainfrom
fix/g17-one-compute-cell-lock

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: A lockdep kernel on J714s reported possible recursive locking on g17::ComputeCell::queue in publish_compute_on(). select_compute_channel() kept the best queue locked while it locked the next one. It now compares plain keys, so it holds one queue at a time. It can't deadlock today, but the report switches lockdep off, so it hides any later one.
Tested: no Mac at 1c7275a8414c yet. Build only: drivers/gpu/drm/asahi/ with W=1 has 0 errors and the same warnings as main, the g17 host tests pass 337/337, and checkpatch --strict is clean.
Risk: two-way door · M5 Pro (only there does an owner have more than one compute channel, up to three). J700 and the other G17 Macs run the same function with one channel; its choice is unchanged.
Not yet: a J714s rerun of the lockdep stress that produced the report, and a J700 no-regression row.

Details

min_by_key() ran on the queue guards themselves. It keeps the best item while it pulls the next one, and here an item is a locked cell:

compute_packet() / compute_inline()    device mutex (g17::Shared::state)
  publish_claimed()                    outer_compute
    publish_compute_on()
      select_compute_channel()         cell A (the best so far)
                                         cell B (the next one)   <- the report

Why it isn't a deadlock:

  • The two cells are distinct: every registry entry has its own cell.
  • select_compute_channel() always runs with the device mutex held, so only one thread at a time can hold two cells. It takes them in registry order.
  • The paths without the device mutex (compute_direct(), compute_readiness(), hold_claim()) hold one cell at a time. While they hold it, they take no second cell, no device mutex and no outer_compute.

This was the only walk over the cells that kept a guard while it took the next one. The other min_by_key() users over the cells already map to a key and a QID first; this one now does the same. The walk also no longer makes a direct publisher of the best queue wait while it is blocked on another queue's lock.

Evidence

From the J714s lockdep kernel (main 37a630623169 + #3681, 240 s GPU stress), shortened:

kworker/u76:5 is trying to acquire lock:
ffff0000ac6219e8 (g17::ComputeCell::queue){+.+.}-{4:4}
but task is already holding lock:
ffff0000a958a528 (g17::ComputeCell::queue){+.+.}-{4:4}
 #2: (g17::Shared::state)  #3: (g17::Backend::outer_compute)  #4: (g17::ComputeCell::queue)
 publish_compute_on+0x728/0xae0
 publish_claimed+0x144/0x18c
 <runtime::Backend as job::Backend>::publish
 run_job_cb / drm_sched_run_job_work

debug_locks in /proc/lockdep_stats went from 1 before the stress to 0 after it. #3681 doesn't touch this file; main has the same code.

Local checks at this head (base main 5f32aa72fa7e):

  • make W=1 drivers/gpu/drm/asahi/ (arm64, LLVM, asahi profile): base 41 warnings, head 41, same text, 0 errors.
  • tools/asahi/run-host-tests.py --only g17: 337/337. --only m3-stamp-admission: 2/2.
  • checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.

A lockdep kernel on J714s (M5 Pro) reports a possible recursive lock on
g17::ComputeCell::queue during the GPU stress, from
publish_compute_on(): one cell is locked while another is held.

select_compute_channel() runs min_by_key() on the locked queues
themselves. min_by_key() keeps the best item while it looks at the next
one, so the best queue's cell stays locked while the next cell is being
locked. All other walks over the cells hold one cell at a time.

It cannot deadlock: the cells are distinct, only a holder of the device
mutex takes a second one, and direct publishers hold one cell and never
wait for the device mutex. But the walk can stall a direct publisher on
the held cell, and lockdep turns itself off after the report, so it
hides every later one.

Read the key and the QID of each queue under its own lock and compare
the keys. The choice is unchanged.

Fixes: 7bb65ce ("drm/asahi: g17: fan M5 Pro compute out to sibling channels for sustained heavy kicks")
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 02:55
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 1c7275a8: ready to merge

Check Detail
CI at head ok 9 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 1c7275a8
Conflicts ok none
PR text ok Risk: two-way · M5 Pro (only there does an owner have more than one compute channel, up to three). J700 and the other G17 Macs run the same function with one channel; its choice is unchanged.

Areas: area:gpu
Merge: gh pr merge 4039 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1c7275a. The iterator keeps the same channel selection key and returns an owned key/QID pair, so each cell guard drops before the next cell is locked. The reported host checks pass. A J714s lockdep rerun is pending.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (Apple M5 Pro / T6050 / G17S B1) verification on exact head 1c7275a8414c — no regression at 1c7275a8414c (non-lockdep stock config).

  • Kernel: 7.3.0-m5-a2-4074-4039 (6985e45ab583 + #4074 6aee22f46165 + #4039 1c7275a8414c + A2 Phase 2; vmlinux 6874e0c37cba, aurora.ko 6b762986e786, boot 4888cd85-0747-4351-b5bd-4de09875a32c, SLC 16 planes).
  • Lockdep note: CONFIG_PROVE_LOCKING / lockdep was off in this kernel, so this run verifies functional stability and zero regressions only; it does not claim the J714s lockdep report is cleared (lockdep stress remains pending a lockdep-enabled boot).
  • Multi-queue + timeline Vulkan CTS (rtgen2n31rc24 6e9190bc5ecd, headless WSI, --procs 2): 34,695 Pass / 7,149 NotSupported / 0 Fail / 41,844 total.
  • Concurrent queue create/teardown stress (queue_stress, 4 threads × 25 iters = 100 devices, 3 queue families): QUEUE_STRESS_PASS.
  • Headless gpubench-vk + gpubench-rt-vk: PASS.
  • dmesg / capacity: 0 GPU faults, 0 recoveries/timeouts/lockups/BUG/WARNING, kept_pairs=0, clean handback to stock 7.3.0-m5-pr67 (0fb0b75d).

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants