public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jérôme Pouiller" <jerome.pouiller@silabs.com>
To: Jia-Ju Bai <baijiaju1990@gmail.com>, Hillf Danton <hdanton@sina.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] staging: wfx: possible deadlock in wfx_conf_tx() and wfx_add_interface()
Date: Tue, 01 Feb 2022 12:56:01 +0100	[thread overview]
Message-ID: <1710740.8zh8KgFqrM@pc-42> (raw)
In-Reply-To: <20220201113303.3883-1-hdanton@sina.com>

Hello,

On Tuesday 1 February 2022 12:33:03 CET Hillf Danton wrote:
> On Tue, 1 Feb 2022 15:09:34 +0800 Jia-Ju Bai wrote:
> > Hello,
> >
> > My static analysis tool reports a possible deadlock in the wfx driver in
> > Linux 5.16:
> >
> > wfx_conf_tx()
> >    mutex_lock(&wdev->conf_mutex); --> Line 225 (Lock A)
> >    wfx_update_pm()
> >      wait_for_completion_timeout(&wvif->set_pm_mode_complete, ...); -->
> > Line 3019 (Wait X)
> >
> > wfx_add_interface()
> >    mutex_lock(&wdev->conf_mutex); --> Line 737 (Lock A)
> >    complete(&wvif->set_pm_mode_complete); --> Line 758 (Wake X)
> >
> > When wfx_conf_tx() is executed, "Wait X" is performed by holding "Lock
> > A". If wfx_add_interface() is executed at this time, "Wake X" cannot be
> > performed to wake up "Wait X" in wfx_conf_tx(), because "Lock A" has
> > been already hold by wfx_conf_tx(), causing a possible deadlock.
> > I find that "Wait X" is performed with a timeout, to relieve the
> > possible deadlock; but I think this timeout can cause inefficient execution.
> >
> > 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
> 
> Hey Jia-Ju
> 
> Thank you for reporting it.
> 
> Given the init_completion() prior to complete() in wfx_add_interface(),
> no waiter is waken up by the complete(), so it has nothing to do with
> the waiter in the conf path.

Absolutely. The completion is done by wfx_hif_pm_mode_complete_indication()
(which is not behind a mutex).

> BTW if the unusual wfx init is a real use case then we can add a new helper.

Indeed, it could make the code better. I don't know if there would be other
users.


-- 
Jérôme Pouiller



  parent reply	other threads:[~2022-02-01 11:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01  7:09 [BUG] staging: wfx: possible deadlock in wfx_conf_tx() and wfx_add_interface() Jia-Ju Bai
     [not found] ` <20220201113303.3883-1-hdanton@sina.com>
2022-02-01 11:56   ` Jérôme Pouiller [this message]
2022-02-05  8:34   ` Jia-Ju Bai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1710740.8zh8KgFqrM@pc-42 \
    --to=jerome.pouiller@silabs.com \
    --cc=baijiaju1990@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox