linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	kyletso@google.com, jackp@codeaurora.org,
	andy.shevchenko@gmail.com, unixbhaskar@gmail.com,
	subbaram@codeaurora.org, mrana@codeaurora.org,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] usb: typec: ucsi: possible deadlock in ucsi_pr_swap() and ucsi_handle_connector_change()
Date: Thu, 10 Feb 2022 16:30:23 +0200	[thread overview]
Message-ID: <YgUhf9o5F98dZyxn@kuha.fi.intel.com> (raw)
In-Reply-To: <43d6c3b5-17e6-63a8-21fa-3ff9f478ada7@gmail.com>

On Thu, Feb 10, 2022 at 10:24:42AM +0800, Jia-Ju Bai wrote:
> 
> 
> On 2022/2/9 22:30, Heikki Krogerus wrote:
> > On Wed, Feb 09, 2022 at 11:50:57AM +0800, Jia-Ju Bai wrote:
> > > Hello,
> > > 
> > > My static analysis tool reports a possible deadlock in the ucsi driver in
> > > Linux 5.16:
> > > 
> > > ucsi_pr_swap()
> > >    mutex_lock(&con->lock); --> Line 962 (Lock A)
> > >    wait_for_completion_timeout(&con->complete, ...) --> Line 981 (Wait X)
> > > 
> > > ucsi_handle_connector_change()
> > >    mutex_lock(&con->lock); --> Line 763 (Lock A)
> > >    complete(&con->complete); --> Line 782 (Wake X)
> > >    complete(&con->complete); --> Line 807 (Wake X)
> > > 
> > > When ucsi_pr_swap() is executed, "Wait X" is performed by holding "Lock A".
> > > If ucsi_handle_connector_change() is executed at this time, "Wake X" cannot
> > > be performed to wake up "Wait X" in ucsi_handle_connector_change(), because
> > > "Lock A" has been already held by ucsi_handle_connector_change(), 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.
> > > Any feedback would be appreciated, thanks :)
> > This is probable a regression from commit ad74b8649bea ("usb: typec:
> > ucsi: Preliminary support for alternate modes"). Can you test does
> > this patch fix the issue (attached)?
> 
> Hi Heikki,
> 
> Thanks for the reply and patch.
> After the patch is used, my tool does not report this deadlock in the ucsi
> driver.
> Thus, I think this patch should be okay to fix the deadlock :)

Thanks for testing it. I'll tag you as the reporter and tester in the
patch.

Br,

-- 
heikki

  reply	other threads:[~2022-02-10 14:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09  3:50 [BUG] usb: typec: ucsi: possible deadlock in ucsi_pr_swap() and ucsi_handle_connector_change() Jia-Ju Bai
2022-02-09 14:30 ` Heikki Krogerus
2022-02-10  2:24   ` Jia-Ju Bai
2022-02-10 14:30     ` Heikki Krogerus [this message]
2022-03-25 20:39   ` Jack Pham
2022-03-28  8:28     ` Heikki Krogerus

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=YgUhf9o5F98dZyxn@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=kyletso@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mrana@codeaurora.org \
    --cc=subbaram@codeaurora.org \
    --cc=unixbhaskar@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).