Skip to contentSkip to conversation

fpga: dfl: possible ABBA deadlock in dfl_fpga_cdev_assign_port() and fme_pr()

BUG Jia-Ju Bai 2 participants 2 messages Nov 23, 2021 – Nov 24, 2021 FPGA manager framework

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

Hello,

My static analysis tool reports a possible ABBA deadlock in the dfl driver in Linux 5.10:

dfl_fpga_cdev_assign_port() mutex_lock(&cdev->lock); --> Line 1067 (Lock A) mutex_lock(&pdata->lock); --> Line 1624 (Lock B)

fme_pr()
  mutex_lock(&pdata->lock); --> Line 126 (Lock B) fpga_region_program_fpga()
    fpga_bridges_enable()
      fpga_bridge_enable()
        fme_bridge_enable_set() --> function pointer via "bridge->br_ops->enable_set()" dfl_fpga_cdev_find_port()
            mutex_lock(&cdev->lock); --> Line 499 (LockA)

When dfl_fpga_cdev_assign_port() and fme_pr() are concurrently executed, the deadlock can occur.

I am not quite sure whether this possible deadlock is real and how to fix it if it is real. Any feedback would be appreciated, thanks

Best wishes,
Jia-Ju Bai

#1 lore raw
Quoted 4 lines

dfl_fpga_cdev_assign_port()
  mutex_lock(&cdev->lock); --> Line 1067 (Lock A) mutex_lock(&pdata->lock); --> Line 1624 (Lock B)

This lock is from port platform device.

Quoted 3 lines

fme_pr()
  mutex_lock(&pdata->lock); --> Line 126 (Lock B)

This lock is from fme platform device.

Actually they are different locks, but yes, maybe we should consider improving the naming to avoid misunderstanding.

Thanks
Hao

Quoted 20 lines

  fpga_region_program_fpga() fpga_bridges_enable()
      fpga_bridge_enable() fme_bridge_enable_set() --> function pointer via
"bridge->br_ops->enable_set()"
          dfl_fpga_cdev_find_port() mutex_lock(&cdev->lock); --> Line 499 (LockA)

When dfl_fpga_cdev_assign_port() and fme_pr() are concurrently executed, the deadlock can occur.

I am not quite sure whether this possible deadlock is real and how to fix it if it is real.
Any feedback would be appreciated, thanks

Best wishes,
Jia-Ju Bai