linux-loongson/drivers/ptp
Jeongjun Park 2efe41234d ptp: prevent possible ABBA deadlock in ptp_clock_freerun()
syzbot reported the following ABBA deadlock:

       CPU0                           CPU1
       ----                           ----
  n_vclocks_store()
    lock(&ptp->n_vclocks_mux) [1]
        (physical clock)
                                     pc_clock_adjtime()
                                       lock(&clk->rwsem) [2]
                                        (physical clock)
                                       ...
                                       ptp_clock_freerun()
                                         ptp_vclock_in_use()
                                           lock(&ptp->n_vclocks_mux) [3]
                                              (physical clock)
    ptp_clock_unregister()
      posix_clock_unregister()
        lock(&clk->rwsem) [4]
          (virtual clock)

Since ptp virtual clock is registered only under ptp physical clock, both
ptp_clock and posix_clock must be physical clocks for ptp_vclock_in_use()
to lock &ptp->n_vclocks_mux and check ptp->n_vclocks.

However, when unregistering vclocks in n_vclocks_store(), the locking
ptp->n_vclocks_mux is a physical clock lock, but clk->rwsem of
ptp_clock_unregister() called through device_for_each_child_reverse()
is a virtual clock lock.

Therefore, clk->rwsem used in CPU0 and clk->rwsem used in CPU1 are
different locks, but in lockdep, a false positive occurs because the
possibility of deadlock is determined through lock-class.

To solve this, lock subclass annotation must be added to the posix_clock
rwsem of the vclock.

Reported-by: syzbot+7cfb66a237c4a5fb22ad@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7cfb66a237c4a5fb22ad
Fixes: 73f37068d5 ("ptp: support ptp physical/virtual clocks conversion")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20250728062649.469882-1-aha310510@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-08-12 14:17:35 -07:00
..
Kconfig ptp: Do not enable by default during compile testing 2025-04-22 18:43:10 -07:00
Makefile s390/time: Add PtP driver 2024-10-30 17:02:39 -07:00
ptp_chardev.c ptp: Enable auxiliary clocks for PTP_SYS_OFFSET_EXTENDED 2025-07-03 15:36:06 +02:00
ptp_clock.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-06-19 13:00:24 -07:00
ptp_clockmatrix.c net: ptp: introduce .supported_extts_flags to ptp_clock_info 2025-04-15 20:20:57 -07:00
ptp_clockmatrix.h
ptp_dfl_tod.c
ptp_dte.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
ptp_fc3.c net: ptp: introduce .supported_extts_flags to ptp_clock_info 2025-04-15 20:20:57 -07:00
ptp_fc3.h
ptp_idt82p33.c net: ptp: introduce .supported_extts_flags to ptp_clock_info 2025-04-15 20:20:57 -07:00
ptp_idt82p33.h
ptp_ines.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
ptp_kvm_arm.c
ptp_kvm_common.c
ptp_kvm_x86.c ptp: kvm: x86: Return EOPNOTSUPP instead of ENODEV from kvm_arch_ptp_init() 2024-12-06 17:38:11 -08:00
ptp_mock.c time/timecounter: Fix the lie that struct cyclecounter is const 2025-07-01 15:38:25 +02:00
ptp_ocp.c sysfs: treewide: switch back to attribute_group::bin_attrs 2025-06-17 10:44:15 +02:00
ptp_pch.c ptp_pch: Replace deprecated PCI functions 2024-10-31 18:53:35 -07:00
ptp_private.h ptp: prevent possible ABBA deadlock in ptp_clock_freerun() 2025-08-12 14:17:35 -07:00
ptp_qoriq_debugfs.c
ptp_qoriq.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
ptp_s390.c s390/time: Add PtP driver 2024-10-30 17:02:39 -07:00
ptp_sysfs.c ptp: fix integer overflow in max_vclocks_store 2024-06-18 13:26:44 -07:00
ptp_vclock.c ptp: prevent possible ABBA deadlock in ptp_clock_freerun() 2025-08-12 14:17:35 -07:00
ptp_vmclock.c ptp: vmclock: Remove goto-based cleanup logic 2025-02-11 10:20:52 +01:00
ptp_vmw.c ptp/vmware: Use VMware hypercall API 2024-06-25 17:15:47 +02:00