From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CCAFC56201 for ; Tue, 27 Oct 2020 01:19:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6C9E20829 for ; Tue, 27 Oct 2020 01:19:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="L/0DPWpj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503728AbgJ0BTH (ORCPT ); Mon, 26 Oct 2020 21:19:07 -0400 Received: from z5.mailgun.us ([104.130.96.5]:57274 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439552AbgJ0BTG (ORCPT ); Mon, 26 Oct 2020 21:19:06 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1603761545; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=ykRa/SRdEbudabccJMxxWepehMTr63NuIg68ElZPYA8=; b=L/0DPWpjBRb1u6CfUkpf9iK0Se2CCl9Cxg//ZJAsUn2lValpRARsy42bwYPcVREk+8RsoPhu 7KUaMngC0P5myhMTo0f39ZAZUe38UnB6g9/JT9R6RghXfqf1WngGxxLQf1Pri3nveIzJQYJQ WBe25A0Jgh0SIFqBNVl7b4NsBL0= X-Mailgun-Sending-Ip: 104.130.96.5 X-Mailgun-Sid: WyJiZjI2MiIsICJuZXRkZXZAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-east-1.postgun.com with SMTP id 5f97758401bdd11b7948cab0 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 27 Oct 2020 01:19:00 GMT Sender: hemantk=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 3DB17C433CB; Tue, 27 Oct 2020 01:18:59 +0000 (UTC) Received: from [10.46.162.249] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: hemantk) by smtp.codeaurora.org (Postfix) with ESMTPSA id 30096C433C9; Tue, 27 Oct 2020 01:18:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 30096C433C9 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=hemantk@codeaurora.org Subject: Re: [PATCH v9 4/4] bus: mhi: Add userspace client interface driver To: Loic Poulain Cc: Manivannan Sadhasivam , Greg Kroah-Hartman , linux-arm-msm , open list , Jeffrey Hugo , Bhaumik Bhatt , netdev@vger.kernel.org References: <1603495075-11462-1-git-send-email-hemantk@codeaurora.org> <1603495075-11462-5-git-send-email-hemantk@codeaurora.org> From: Hemant Kumar Message-ID: Date: Mon, 26 Oct 2020 18:18:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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