# \[BUG\] net: netronome: nfp: possible deadlock in nfp\_cpp\_area\_acquire() and nfp\_cpp\_area\_release()

- List: netdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/netdev/2022/02/1663603/t

## \[BUG\] net: netronome: nfp: possible deadlock in nfp\_cpp\_area\_acquire() and nfp\_cpp\_area\_release()

- From: Jia-Ju Bai \<hidden\>
- Date: 2022-02-09 03:03:24 
- Message: https://ratatoskr.run/netdev/2022/02/1663603.md

```text
Hello,

My static analysis tool reports a possible deadlock in the nfp driver in Linux 5.16:

nfp_cpp_area_acquire()
  mutex_lock(&area->mutex); --> Line 455 (Lock A)
  __nfp_cpp_area_acquire()
    wait_event_interruptible(area->cpp->waitq, ...) --> Line 427 (Wait X)

nfp_cpp_area_release()
  mutex_lock(&area->mutex); --> Line 502 (Lock A)
  wake_up_interruptible_all(&area->cpp->waitq); --> Line 508 (Wake X)

When nfp_cpp_area_acquire() is executed, "Wait X" is performed by holding "Lock A". If nfp_cpp_area_release() is executed at this time, "Wake X" cannot be performed to wake up "Wait X" in nfp_cpp_area_acquire(), because "Lock A" has been already hold by nfp_cpp_area_acquire(), causing a possible deadlock.

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


Best wishes,
Jia-Ju Bai
```

## Re: \[BUG\] net: netronome: nfp: possible deadlock in nfp\_cpp\_area\_acquire() and nfp\_cpp\_area\_release()

- From: Jakub Kicinski \<kuba@kernel.org\>
- Date: 2022-02-09 04:11:58 
- Message: https://ratatoskr.run/netdev/2022/02/1663676.md

```text
On Wed, 9 Feb 2022 10:50:44 +0800 Jia-Ju Bai wrote:
> Hello,
> 
> My static analysis tool reports a possible deadlock in the nfp driver in 
> Linux 5.16:
> 
> nfp_cpp_area_acquire()
>    mutex_lock(&area->mutex); --> Line 455 (Lock A)
>    __nfp_cpp_area_acquire()
>      wait_event_interruptible(area->cpp->waitq, ...) --> Line 427 (Wait X)
> 
> nfp_cpp_area_release()
>    mutex_lock(&area->mutex); --> Line 502 (Lock A)
>    wake_up_interruptible_all(&area->cpp->waitq); --> Line 508 (Wake X)
> 
> When nfp_cpp_area_acquire() is executed, "Wait X" is performed by 
> holding "Lock A". If nfp_cpp_area_release() is executed at this time, 
> "Wake X" cannot be performed to wake up "Wait X" in 
> nfp_cpp_area_acquire(), because "Lock A" has been already hold by 
> nfp_cpp_area_acquire(), causing a possible deadlock.
> 
> I am not quite sure whether this possible problem is real and how to fix 
> it if it is real.

It's not.

> Any feedback would be appreciated, thanks :)
>
>
> Best wishes,
> Jia-Ju Bai

```
