Repository navigation
accel/ane: register the PM notifier outside the driver lock (lockdep ABBA) - #2505
Conversation
…lock ane_h16_pin() registered the PM notifier while ane_h16_lock was held (ane_h16_start_work() -> ane_h16_advance() -> ane_h16_scratch_boot()), which orders the PM chain rwsem after ane_h16_lock. ane_h16_pm_event() runs with that rwsem held and takes ane_h16_lock, so lockdep reports a possible circular dependency on the first system sleep after the engine comes up: WARNING: possible circular locking dependency detected rtcwake is trying to acquire lock: ane_h16_lock, at: ane_h16_pm_event but task is already holding lock: (pm_chain_head).rwsem Register the notifier once at probe, after ane_h16_lock is dropped and before the start work can pin the device, and let it return NOTIFY_DONE until the device is pinned, which is what an unregistered notifier did. Pinning now only sets the flag. A device removed before it was pinned unregisters the notifier outside the lock. The debugfs stage write could also pin the device; it now takes the system sleep lock like the start work, so pinning never lands inside a sleep transition. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
ane_fw_retain() registers the PM notifier, and both of its callers hold b->lock: the parked start (ane_fw_start_work() -> ane_fw_register_parked()) and the "map" stage (ane_fw_stage_action()). ane_fw_pm_event() runs with the PM chain rwsem held and takes b->lock in ane_fw_sleep_resume() and ane_fw_sleep_prepare(), which is the same lock inversion as on H16. Register the notifier once in ane_fw_staged_init(), outside b->lock, and return NOTIFY_DONE from it until the backend is retained, which is what an unregistered notifier did. Retaining happens under the system sleep lock on every path, so it never changes inside a transition. ane_fw_staged_exit() unregisters it for a backend that was never retained. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Approving. The ABBA is real: register_pm_notifier() takes the PM chain rwsem for write, and the callback runs under it for read and then takes the driver lock. Registering once at probe/init, outside the lock, fixes the order on both backends.
The early NOTIFY_DONE while not pinned or retained is safe because every first pin or retain happens under lock_system_sleep(). That covers H16 ane_h16_start_work() and the stage file (now also under it), and H17 ane_fw_start_work(), ane_fw_first_bringup() and the stage store. The flag can't flip between PREPARE and POST. H16 recovery needs program_ready, so it only runs after the first pin. The unregister paths look right: H16 remove drops the notifier only when it isn't kept, and H17 exit only when not retained. The H16 probe failure path unwinds debugfs and the drvdata.
PROVE_LOCKING rows on the Neo (H17, 0 vs 2/2 with the old module) and the J616s (H16) cover both backends.
Heads-up: #2240 (niteria) touches the same two files, so it will need a rebase after this lands.
Problem
Both ANE backends register their PM notifier while holding their own lock, and the notifier takes that same lock when the PM chain calls it:
ane_h16_backend.c):ane_h16_pin()callsregister_pm_notifier()withane_h16_lockheld (ane_h16_start_work()->ane_h16_advance()->ane_h16_scratch_boot()).ane_h16_pm_event()takesane_h16_lock.ane_fw_cold.c):ane_fw_retain()registers it underb->lock, fromane_fw_register_parked()and from the "map" stage.ane_fw_pm_event()takesb->lockinane_fw_sleep_prepare()andane_fw_sleep_resume().That orders the PM chain rwsem after the driver lock in one path and before it in the other. With
PROVE_LOCKING, the first system sleep after the engine comes up logs "possible circular locking dependency detected" and lockdep switches itself off for the rest of the boot.Change
Two commits, one per backend, same shape:
ane_fw_staged_init()(H17), with no driver lock held, and before the start work that can pin or retain the device.NOTIFY_DONEright away, which is what an unregistered notifier did. Pinning and retaining only set the flag now.Testing
Lockdep kernels (
PROVE_LOCKING,DEBUG_LOCKDEP,DEBUG_ATOMIC_SLEEP) on integration/aurora 2c35f50 with #2240 (f1623ba) and this branch merged:debug_locks1, replay identical after wakeane_t6021.kobuilt without this branch&b->lockinane_fw_pm_eventvs(pm_chain_head).rwsemfromregister_pm_notifierinane_fw_start_work(2 of 2 boots)debug_locks1, replay identical after wakeane_h16_lockinane_h16_pm_eventvs(pm_chain_head).rwsemfromregister_pm_notifierinane_h16_pincheckpatch
--strictis clean on both commits. The branch merges cleanly with #1768, #1863, #1899, #1957 and #2240.Still to run
Nothing for this change.
Lockdep report before the change (H17, Neo)
The H16 report on the M4 Pro has the same shape with
ane_h16_lock,ane_h16_pin()andane_h16_pm_event().ANE rows on the Neo with this branch (lockdep on)
Assisted-by: LLM (Claude:Opus 5.5)