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=-5.2 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,URIBL_BLOCKED,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 57C0EC64E7B for ; Tue, 1 Dec 2020 17:43:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE7A320870 for ; Tue, 1 Dec 2020 17:43:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="Butl8+3L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729165AbgLARnV (ORCPT ); Tue, 1 Dec 2020 12:43:21 -0500 Received: from m42-5.mailgun.net ([69.72.42.5]:60229 "EHLO m42-5.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgLARnV (ORCPT ); Tue, 1 Dec 2020 12:43:21 -0500 X-Greylist: delayed 326 seconds by postgrey-1.27 at vger.kernel.org; Tue, 01 Dec 2020 12:43:20 EST DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1606844581; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=lExQYH3Hcu6IMfr6Uk4+ulaceeEs8V2qygtLsani6Fo=; b=Butl8+3L9m4JWi6lJA7Vz5wAGf1D5uMj36rvVcm02rRloPJsbudbD/bElTUG1/CyWgiG+87p azFEHlwlsteFca+6kcLzxR9pHffMnOTTEXMmWdrOInrzgiyQtIJcfqEZqZAnI4aLt8PlF0kw g2MhD+nEs7RGvDhEYQRhocZFQAA= X-Mailgun-Sending-Ip: 69.72.42.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 5fc67f3f875646f1e977970e (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 01 Dec 2020 17:37:03 GMT Sender: jhugo=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id CA943C43461; Tue, 1 Dec 2020 17:37:02 +0000 (UTC) Received: from [10.226.59.216] (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: jhugo) by smtp.codeaurora.org (Postfix) with ESMTPSA id 87A5CC43460; Tue, 1 Dec 2020 17:37:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 87A5CC43460 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=jhugo@codeaurora.org Subject: Re: [PATCH v13 4/4] bus: mhi: Add userspace client interface driver To: Loic Poulain , Hemant Kumar Cc: Manivannan Sadhasivam , Greg Kroah-Hartman , linux-arm-msm , open list , Bhaumik Bhatt , Network Development References: <1606533966-22821-1-git-send-email-hemantk@codeaurora.org> <1606533966-22821-5-git-send-email-hemantk@codeaurora.org> From: Jeffrey Hugo Message-ID: <1247e32e-ed67-de6b-81ec-3bde9ad93250@codeaurora.org> Date: Tue, 1 Dec 2020 10:37:00 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 12/1/2020 10:36 AM, Loic Poulain wrote: > On Tue, 1 Dec 2020 at 02:16, Hemant Kumar wrote: >> >> Hi Loic, >> >> On 11/30/20 10:22 AM, Loic Poulain wrote: >>> On Sat, 28 Nov 2020 at 04:26, Hemant Kumar wrote: >>>> >>>> This MHI client driver allows userspace clients to transfer >>>> raw data between MHI device and host using standard file operations. >>>> Driver instantiates UCI device object which is associated to device >>>> file node. UCI device object instantiates UCI channel object when device >>>> file node is opened. UCI channel object is used to manage MHI channels >>>> by calling MHI core APIs for read and write operations. MHI channels >>>> are started as part of device open(). MHI channels remain in start >>>> state until last release() is called on UCI device file node. Device >>>> file node is created with format >>> >>> [...] >>> >>>> +struct uci_chan { >>>> + struct uci_dev *udev; >>>> + wait_queue_head_t ul_wq; >>>> + >>>> + /* ul channel lock to synchronize multiple writes */ >>>> + struct mutex write_lock; >>>> + >>>> + wait_queue_head_t dl_wq; >>>> + >>>> + /* dl channel lock to synchronize multiple reads */ >>>> + struct mutex read_lock; >>>> + >>>> + /* >>>> + * protects pending list in bh context, channel release, read and >>>> + * poll >>>> + */ >>>> + spinlock_t dl_pending_lock; >>>> + >>>> + struct list_head dl_pending; >>>> + struct uci_buf *cur_buf; >>>> + size_t dl_size; >>>> + struct kref ref_count; >>>> +}; >>> >>> [...] >>> >>>> + * struct uci_dev - MHI UCI device >>>> + * @minor: UCI device node minor number >>>> + * @mhi_dev: associated mhi device object >>>> + * @uchan: UCI uplink and downlink channel object >>>> + * @mtu: max TRE buffer length >>>> + * @enabled: Flag to track the state of the UCI device >>>> + * @lock: mutex lock to manage uchan object >>>> + * @ref_count: uci_dev reference count >>>> + */ >>>> +struct uci_dev { >>>> + unsigned int minor; >>>> + struct mhi_device *mhi_dev; >>>> + struct uci_chan *uchan; >>> >>> Why a pointer to uci_chan and not just plainly integrating the >>> structure here, AFAIU uci_chan describes the channels and is just a >>> subpart of uci_dev. That would reduce the number of dynamic >>> allocations you manage and the extra kref. do you even need a separate >>> structure for this? >> >> This goes back to one of my patch versions i tried to address concern >> from Greg. Since we need to ref count the channel as well as the uci >> device i decoupled the two objects and used two reference counts for two >> different objects. > > What Greg complained about is the two kref in the same structure and > that you were using kref as an open() counter. But splitting your > struct in two in order to keep the two kref does not make the much > code better (and simpler). I'm still a bit puzzled about the driver > complexity, it's supposed to be just a passthrough interface to MHI > after all. > > I would suggest several changes, that IMHO would simplify reviewing: > - Use only one structure representing the 'uci' context (uci_dev) > - Keep the read path simple (mhi_uci_read), do no use an intermediate > cur_buf pointer, only dequeue the buffer when it is fully consumed. > - As I commented before, take care of the dl_pending list access > concurrency, even in wait_event. > - You don't need to count the number of open() calls, AFAIK, > mhi_prepare_for_transfer() simply fails if channels are already > started... Unless I missed something, you seem to have ignored the root issue that Hemant needs to solve, which is when to call mhi_unprepare_for_transfer(). You can't just call that when close() is called because there might be multiple users, and each one is going to trigger a close(), so you need to know how many close() instances to expect, and only call mhi_unprepare_for_transfer() for the last one. -- Jeffrey Hugo Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.