linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hemant Kumar <hemantk@codeaurora.org>
To: Loic Poulain <loic.poulain@linaro.org>
Cc: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	Jeffrey Hugo <jhugo@codeaurora.org>,
	Bhaumik Bhatt <bbhatt@codeaurora.org>,
	netdev@vger.kernel.org
Subject: Re: [PATCH v9 4/4] bus: mhi: Add userspace client interface driver
Date: Mon, 26 Oct 2020 18:18:57 -0700	[thread overview]
Message-ID: <aefee6d1-da2c-d081-6bda-b9bd49e8c12f@codeaurora.org> (raw)
In-Reply-To: <CAMZdPi_MQ0SqK7s6h_1_9yEDD0vuAOpCTjSHTd1PBsGjvXukiA@mail.gmail.com>

Hi Loic,

On 10/26/20 10:34 AM, Loic Poulain wrote:
> Hi Hemant,
> 
> That looks better IMHO, just small comments on locking.
> 
[..]
>     +static ssize_t mhi_uci_write(struct file *file,
>     +                            const char __user *buf,
>     +                            size_t count,
>     +                            loff_t *offp)
>     +{
>     +       struct uci_dev *udev = file->private_data;
>     +       struct mhi_device *mhi_dev = udev->mhi_dev;
>     +       struct device *dev = &mhi_dev->dev;
>     +       struct uci_chan *uchan = udev->uchan;
>     +       size_t bytes_xfered = 0;
>     +       int ret, nr_avail = 0;
>     +
>     +       /* if ul channel is not supported return error */
>     +       if (!buf || !count || !mhi_dev->ul_chan)
>     +               return -EINVAL;
>     +
>     +       dev_dbg(dev, "%s: to xfer: %zu bytes\n", __func__, count);
>     +
>     +       mutex_lock(&uchan->write_lock);
> 
> 
> Maybe mutex_lock_interruptible is more appropriate here (same in read fops).
i agree, will return -EINTR if mutex_lock_interruptible returns < 0.
> 
[..]
>     +static ssize_t mhi_uci_read(struct file *file,
>     +                           char __user *buf,
>     +                           size_t count,
>     +                           loff_t *ppos)
>     +{
>     +       struct uci_dev *udev = file->private_data;
>     +       struct mhi_device *mhi_dev = udev->mhi_dev;
>     +       struct uci_chan *uchan = udev->uchan;
>     +       struct device *dev = &mhi_dev->dev;
>     +       struct uci_buf *ubuf;
>     +       size_t rx_buf_size;
>     +       char *ptr;
>     +       size_t to_copy;
>     +       int ret = 0;
>     +
>     +       /* if dl channel is not supported return error */
>     +       if (!buf || !mhi_dev->dl_chan)
>     +               return -EINVAL;
>     +
>     +       mutex_lock(&uchan->read_lock);
>     +       spin_lock_bh(&uchan->dl_pending_lock);
>     +       /* No data available to read, wait */
>     +       if (!uchan->cur_buf && list_empty(&uchan->dl_pending)) {
>     +               dev_dbg(dev, "No data available to read, waiting\n");
>     +
>     +               spin_unlock_bh(&uchan->dl_pending_lock);
>     +               ret = wait_event_interruptible(uchan->dl_wq,
>     +                                              (!udev->enabled ||
>     +                                           
>       !list_empty(&uchan->dl_pending)));
> 
> 
> If you need to protect dl_pending list against concurent access, you 
> need to do it in wait_event as well. I would suggest to lookg at 
> `wait_event_interruptible_lock_irq` function, that allows to pass a 
> locked spinlock as parameter. That would be safer and prevent this 
> lock/unlock dance.
When using this API difference is, first we take spin_lock_bh() and then 
wait API is using spin_unlock_irq()/spin_lock_irq(). I am getting
"BUG: scheduling while atomic" when i use this way. When i changed 
spin_lock_bh to spin_lock_irq then we got rid of the kernel BUG.

Thanks,
Hemant

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

      parent reply	other threads:[~2020-10-27  1:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23 23:17 [PATCH v9 0/4] userspace MHI client interface driver Hemant Kumar
2020-10-23 23:17 ` [PATCH v9 1/4] bus: mhi: core: Add helper API to return number of free TREs Hemant Kumar
2020-10-23 23:17 ` [PATCH v9 2/4] bus: mhi: core: Move MHI_MAX_MTU to external header file Hemant Kumar
2020-10-23 23:17 ` [PATCH v9 3/4] docs: Add documentation for userspace client interface Hemant Kumar
2020-10-25 21:46   ` Jakub Kicinski
2020-10-26 13:38     ` Jeffrey Hugo
2020-10-26 13:46       ` Dan Williams
2020-10-26 13:56         ` Jeffrey Hugo
2020-10-26 22:36           ` Hemant Kumar
2020-10-26 22:56       ` Jakub Kicinski
2020-10-26 23:22         ` Hemant Kumar
2020-10-23 23:17 ` [PATCH v9 4/4] bus: mhi: Add userspace client interface driver Hemant Kumar
     [not found]   ` <CAMZdPi_MQ0SqK7s6h_1_9yEDD0vuAOpCTjSHTd1PBsGjvXukiA@mail.gmail.com>
2020-10-27  1:18     ` Hemant Kumar [this message]

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=aefee6d1-da2c-d081-6bda-b9bd49e8c12f@codeaurora.org \
    --to=hemantk@codeaurora.org \
    --cc=bbhatt@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhugo@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=netdev@vger.kernel.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 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).