Re: [PATCH net] ptp: prevent possible ABBA deadlock in ptp_clock_freerun()
From: Jeongjun Park <hidden>
Date: 2025-07-16 05:12:39
Also in:
lkml
Hello, Jakub Kicinski [off-list ref] wrote:
On Sat, 5 Jul 2025 23:50:31 +0900 Jeongjun Park wrote:quoted
ABBA deadlock occurs in the following scenario: CPU0 CPU1 ---- ---- n_vclocks_store() lock(&ptp->n_vclocks_mux) [1] pc_clock_adjtime() lock(&clk->rwsem) [2] ... ptp_clock_freerun() ptp_vclock_in_use() lock(&ptp->n_vclocks_mux) [3] ptp_clock_unregister() posix_clock_unregister() lock(&clk->rwsem) [4] To solve this with minimal patches, we should change ptp_clock_freerun() to briefly release the read lock before calling ptp_vclock_in_use() and then re-lock it when we're done.Dropping locks randomly is very rarely the correct fix.
Of course, we can change it to lock clk->rwsem before calling ptp_clock_unregister(), but it would require a lot of code modifications, and posix_clock_unregister() would also have to be modified, so I don't think it's very appropriate. That's why I suggested a way to briefly release the lock in ptp_clock_freerun().
Either way - you forgot to CC Vladimir, again.
No need to reference Vladimir, as this bug is a structural issue that has been around since the n_vclocks feature was added, as indicated in the Fixes tag.
-- pw-bot: cr
Regards, Jeongjun Park