All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bhaumik Bhatt <bbhatt@codeaurora.org>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org,
	linux-arm-msm@vger.kernel.org,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] bus: mhi: possible ABBA deadlock in mhi_pm_m0_transition() and mhi_send_cmd()
Date: Thu, 15 Jul 2021 09:57:22 -0700	[thread overview]
Message-ID: <2fbeeb8dc647dc88e69ec6624c2078d1@codeaurora.org> (raw)
In-Reply-To: <0a213c92-32d5-efc8-079b-dd20d5ecfe20@gmail.com>

On 2021-07-15 02:45 AM, Jia-Ju Bai wrote:
> Hello,
> 
> I find there is a possible ABBA deadlock in the MHI driver in Linux 
> 5.10:
> 
> In mhi_pm_m0_transition():
> 262:     read_lock_bh(&mhi_cntrl->pm_lock);
> 281:     spin_lock_irq(&mhi_cmd->lock);
> 
> In mhi_send_cmd():
> 1181:   spin_lock_bh(&mhi_cmd->lock);
> 1207:   read_lock_bh(&mhi_cntrl->pm_lock);
> 
> When mhi_pm_m0_transition() and mhi_send_cmd() are concurrently
> executed, the deadlock can occur.
> 
> I check the code and find a possible case of such concurrent execution:
> 
> #CPU1:
> mhi_poll (mhi_event->process_event(...))
>   mhi_process_ctrl_ev_ring
>     mhi_pm_m0_transition
> 
> #CPU2:
> mhi_prepare_for_transfer
>   mhi_prepare_channel
>     mhi_send_cmd
> 
> Note that mhi_poll() and mhi_prepare_for_transfer() are both exported
> by EXPORT_SYMBOL.
> Thus, I guess these two functions could be concurrently called by a MHI 
> driver.
> 
> 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

Few pointers from your example:

1. mhi_poll() is currently not used by any client upstream yet.
2. Polling is not to be used for single event ring (shared control + 
data) cases
since it is meant to be for client drivers with dedicated data packets 
only.
3. mhi_send_cmd() will always be called after an mhi_pm_m0_transition() 
has
completed by design since we wait for the device to be held in M0 prior 
to it.

Would like to know what Mani and Hemant have to say. I don't think we 
can run in
to the scenario from your example so we should be safe.

Thanks,
Bhaumik
---
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2021-07-15 16:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  9:45 [BUG] bus: mhi: possible ABBA deadlock in mhi_pm_m0_transition() and mhi_send_cmd() Jia-Ju Bai
2021-07-15 16:57 ` Bhaumik Bhatt [this message]
2021-07-16  6:45   ` Manivannan Sadhasivam
2021-07-19  2:08     ` 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=2fbeeb8dc647dc88e69ec6624c2078d1@codeaurora.org \
    --to=bbhatt@codeaurora.org \
    --cc=baijiaju1990@gmail.com \
    --cc=hemantk@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.