Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1273000pxx; Tue, 27 Oct 2020 12:23:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx20A7zdSsVrFH9f08yDA7faqzZJdtso8GhgAEAGWcRulYnCUHXM10wCGa1oZTNxNH2LTx/ X-Received: by 2002:a17:906:3290:: with SMTP id 16mr3922691ejw.308.1603826609504; Tue, 27 Oct 2020 12:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603826609; cv=none; d=google.com; s=arc-20160816; b=q5OuwLB0xZBxezthsChCOvMpPG3m+Wfg7JReNKn5xyz2/wP9zAcdWHkyBMmbpkdGpH FDiYielMnRKgrWc9sXnF4fRZSSjwOrrSC5z2o1S+IOgBsCMNYJXXbNQIQQPm28Hcq1xj jqNkTvKzqkBEPgLb78vDi+deENLQLeNMUV7/FW5p0QhrzYSwUphGTVLDKBPz7gZBvcnx vmLhJ136j/V0/Vk/EGeJ2l6GfaWEyKEj2ieR1uPISE/Fdm0C9wtwBcJ+KxubfRL9YYj4 bcS8E4KJeZOrjle3J7hRZegUOFU+8BY4hYEf2KgdrDmk/EhNjM+oHZvoLblG8rsCKoVw 3ndA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dmarc-filter:sender:dkim-signature; bh=ykRa/SRdEbudabccJMxxWepehMTr63NuIg68ElZPYA8=; b=be1DR7q/qi6TzG6lZUwFtN+AaB6aWDjffA9sffothYyPt5lnY/825ZPGi9wjXCDx5J c34GSG1Ldep4H4RXdHQ5R2gv/NU+zxkt9ESYcuBZUtIewHcb7i1U7SmQUMjftqrOyaq2 URxNm30qPovjP9fi02NJbjgK/rce5bRnxtnl4ixQK+rUpXeWPSKPSm9LSjXUjT6G5YhU ZwvlKnlhTxjqkUf9oY4cywHIyio1zN34L1h+loT7+lRwbinAKfsKGHYmkJ1SmmggK1ER va99E69+EX5ZPp6KpFk1m2c41pUL7/kWNcTg4XPUbFUPPOgiZH0js/Yvh2LvFRF+s/ji c2EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="L/0DPWpj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h26si1530269edz.138.2020.10.27.12.23.02; Tue, 27 Oct 2020 12:23:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="L/0DPWpj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503726AbgJ0BTH (ORCPT + 99 others); Mon, 26 Oct 2020 21:19:07 -0400 Received: from z5.mailgun.us ([104.130.96.5]:55206 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411311AbgJ0BTG (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: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd 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 5f97758401bdd11b7948caaf (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) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL autolearn=unavailable autolearn_force=no version=3.4.0 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: linux-kernel@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