Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp231280pxu; Tue, 1 Dec 2020 09:51:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxB3T5RB8UeVr6HfRoY9YL8UTK4bhNGAVgFnL4K0EYtL9CTVSm8ZYRKQrotgg14ivv/3dNv X-Received: by 2002:aa7:da01:: with SMTP id r1mr4254500eds.45.1606845085516; Tue, 01 Dec 2020 09:51:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606845085; cv=none; d=google.com; s=arc-20160816; b=gMMUEm7WfCUbuoL9QqBzhIy61w/H7DGd6g1baZGZOypLiIjseXfhxRD2X05W8mOo6a mP2WOb2hfBq9bhDHkv2iEZdWtMHxs5z4q5CYtvPzRdWo7M9i14IooMCWwW0zbmCsVA3T YrzOR6tIOXOGBx4NpQ7A6SUGZqKhWcSG1N368IjZj1bGPABmED0gT4SGMSvyjVabHssm QlzNG63SQmB23iuegy+0WQd4nAtOz4faCdk0qxn/WL1mQfPapaGL3M727WWGUrzMTt/c 4+gHf52TrWVPVIDORWUCp+MNAW3fgUrM6A9jmnHBkb195VMkMV00go7vgIUMYeJOe4zO 8EJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VxdwyJsEqW1IFZ+wJlnqk+0jlPNFFTXeNogrQYB17Po=; b=uP7QdIeW/RawVBMuSCVsDcit6WQogdw4Hxzxe+3ssbZofiz0lEtd9xwbw8faBDCEIj ocxtBhWHn/KOeczqhbUAfcFeGhmb9jszvhL0/uUjFImCHqeCg/m9WwEIp/0fQRECrBQH W4aw6bPIdoV8iT7o5nnt9MBg+G2kPucuLAFWYbq4bZrauE7bwTqwqUuLLsuJ9niBTGep NMcgayiARuHI4Q3Gcg2UQBxzwhImlJZGS9wNqC0ss/dDdiFEkFqIs+MU26ekNQOxECMX g8qbmnYAb63K8x1XdOOjbxlTI+QlbPaA3w4oqimomWzbvfXtvjKbkGwGM0HjBqf2FZFs gV6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z5KgBOz6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nq4si465525ejb.115.2020.12.01.09.51.02; Tue, 01 Dec 2020 09:51:25 -0800 (PST) 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=@linaro.org header.s=google header.b=z5KgBOz6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404163AbgLARre (ORCPT + 99 others); Tue, 1 Dec 2020 12:47:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404118AbgLARra (ORCPT ); Tue, 1 Dec 2020 12:47:30 -0500 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87446C0617A6 for ; Tue, 1 Dec 2020 09:46:44 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id n24so4547815edb.4 for ; Tue, 01 Dec 2020 09:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VxdwyJsEqW1IFZ+wJlnqk+0jlPNFFTXeNogrQYB17Po=; b=z5KgBOz6m3zJGbxmCYtcciYdsmGO5nwq6vLp++P5SLGrT+4ama0sk+fQfa3zVW5lJg 1V3BXsSc2kOF7bDFojVIIvTSnqpscsMFywVwEHnBekeZJYLyTZihwG0frVbwlDE6pkLx aEq2EGjGKiwNic83a4TXRS//IyVTn5jZeEUlfOtcQz11Yu8w1VZb8iyTrrKfroVqKixZ 9ZA0r0lMJ/TPhZ3iM9N4o5byG6HALe7q/sGwemZOArDwRyN2CLprQLtASlr+Iyz8Mb5E AIXIySdCk+BTOiOVUsNZpAauxQo6NEjkUkz7bVqamzo95YMsKMuHLyXTXqNHegmviRfR F4/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VxdwyJsEqW1IFZ+wJlnqk+0jlPNFFTXeNogrQYB17Po=; b=RexQani+1/0Q+vIvZ1XWKd3lM33YClCuY266NgcqPFRm5qQK/ssbmzTC52znZyNf0V MYU40zLLr1Xg9RGxQa6VSYMsT0voerlYmC79Xg3NBsMVHXPUenA4zPatbMg/QPfhVQtY 9zPQMW2hhcNrVpBvP02P1M3naviTE5PgRrbCzjhdjrXfnCALGLsnyLB8O6jaD9uHsDH2 FQ6QJcRLPJ/HmvTIOZzg/jwyyZ1Rkr7bsjpzNrs97n66jboAIKUKnLRVO1T85sKBD/OJ ZTeKlZbeNYie+DsNEb1VGVPc/P37uYTzh9560t8veWNecRPOhJrT8p5iwzMx7yDES0Sf Sx1A== X-Gm-Message-State: AOAM531lM0JdMluBL58HRdsN3aj/x2KD2fXsmZTJjQSc5p95jJzrVZE8 gjDbu0xnSZRaHAWqob/8cfB5NBXEDm4rQ7HCDhM2cg== X-Received: by 2002:a50:d886:: with SMTP id p6mr4386383edj.366.1606844803086; Tue, 01 Dec 2020 09:46:43 -0800 (PST) MIME-Version: 1.0 References: <1606533966-22821-1-git-send-email-hemantk@codeaurora.org> <1606533966-22821-5-git-send-email-hemantk@codeaurora.org> <1247e32e-ed67-de6b-81ec-3bde9ad93250@codeaurora.org> In-Reply-To: <1247e32e-ed67-de6b-81ec-3bde9ad93250@codeaurora.org> From: Loic Poulain Date: Tue, 1 Dec 2020 18:52:57 +0100 Message-ID: Subject: Re: [PATCH v13 4/4] bus: mhi: Add userspace client interface driver To: Jeffrey Hugo Cc: Hemant Kumar , Manivannan Sadhasivam , Greg Kroah-Hartman , linux-arm-msm , open list , Bhaumik Bhatt , Network Development Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Dec 2020 at 18:37, Jeffrey Hugo wrote: > > 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. That one part of his problem, yes, but if you unconditionally call mhi_prepare_for_transfer in open(), it should fail for subsequent users, and so only one user will successfully open the device. Regards, Loic