From: Chris Lew <clew@codeaurora.org>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
gregkh@linuxfoundation.org, arnd@arndb.de,
smohanad@codeaurora.org, jhugo@codeaurora.org,
kvalo@codeaurora.org, bjorn.andersson@linaro.org,
hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org
Subject: Re: [PATCH v2 14/16] net: qrtr: Add MHI transport layer
Date: Tue, 11 Feb 2020 17:01:17 -0800 [thread overview]
Message-ID: <9fbcaa0e-cb94-ba8b-42da-379df3a7a1ce@codeaurora.org> (raw)
In-Reply-To: <20200211035020.GA3358@Mani-XPS-13-9360>
On 2/10/2020 7:50 PM, Manivannan Sadhasivam wrote:
> Hi Chris,
>
> On Thu, Feb 06, 2020 at 04:14:19PM -0800, Chris Lew wrote:
>> On 2/4/2020 12:19 AM, Manivannan Sadhasivam wrote:
>>> Hi Jakub,
>>>
>>> On Mon, Feb 03, 2020 at 10:12:25AM -0800, Jakub Kicinski wrote:
>>>> On Fri, 31 Jan 2020 19:20:07 +0530, Manivannan Sadhasivam wrote:
>>>>> +/* From QRTR to MHI */
>>>>> +static void qcom_mhi_qrtr_ul_callback(struct mhi_device *mhi_dev,
>>>>> + struct mhi_result *mhi_res)
>>>>> +{
>>>>> + struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
>>>>> + struct qrtr_mhi_pkt *pkt;
>>>>> + unsigned long flags;
>>>>> +
>>>>> + spin_lock_irqsave(&qdev->ul_lock, flags);
>>>>> + pkt = list_first_entry(&qdev->ul_pkts, struct qrtr_mhi_pkt, node);
>>>>> + list_del(&pkt->node);
>>>>> + complete_all(&pkt->done);
>>>>> +
>>>>> + kref_put(&pkt->refcount, qrtr_mhi_pkt_release);
>>>> Which kref_get() does this pair with?
>>>>
>>>> Looks like qcom_mhi_qrtr_send() will release a reference after
>>>> completion, too.
>>>>
>>> Yikes, there is some issue here...
>>>
>>> Acutally the issue is not in what you referred above but the overall kref
>>> handling itself. Please see below.
>>>
>>> kref_put() should be present in qcom_mhi_qrtr_ul_callback() as it will
>>> decrement the refcount which got incremented in qcom_mhi_qrtr_send(). It
>>> should be noted that kref_init() will fix the refcount to 1 and kref_get() will
>>> increment to 2. So for properly releasing the refcount to 0, we need to call
>>> kref_put() twice.
>>>
>>> So if all goes well, the refcount will get decremented twice in
>>> qcom_mhi_qrtr_ul_callback() as well as in qcom_mhi_qrtr_send() and we are good.
>>>
>>> But, if the transfer has failed ie., when qcom_mhi_qrtr_ul_callback() doesn't
>>> get called, then we are leaking the refcount. I need to rework the kref handling
>>> code in next iteration.
>>>
>>> Thanks for triggering this!
>>>
>>> Regards,
>>> Mani
>>>
>>>>> + spin_unlock_irqrestore(&qdev->ul_lock, flags);
>>>>> +}
>> Hi Mani,
>>
>> I'm not sure if this was changed in your patches but MHI is supposed to give a
>> ul_callback() for any packet that is successfully queued. In the case of the
>> transfer failing, the ul_callback() should still be called so there should
>> be no refcount leaking. It is an essential assumption I made, if that no longer
>> holds true then the entire driver needs to be reworked.
>>
> Your assumption is correct. Only when the packet gets queued into the transfer
> ring, the ul_xfer_cb will be called irrespective of the transfer state (success
> or failure). But when the mhi_queue_transfer() returns even before queuing any
> packet, then we need to decrease the refcount in the error path.
>
> Please correct me if I'm wrong.
The error path for mhi_queue_transfer directly frees the packet structure since no
other context has a reference to those structs. If you wanted to clean it up and converge
using kref release to free, I think that would work. There are some things you'll have to
re-arrange like at what point the packet is added to the ul pkts list.
> Thanks,
> Mani
>
>> Thanks,
>> Chris
>>
>> --
>>
>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
next prev parent reply other threads:[~2020-02-12 1:01 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-31 13:49 [PATCH v2 00/16] Add MHI bus support Manivannan Sadhasivam
2020-01-31 13:49 ` [PATCH v2 01/16] docs: Add documentation for MHI bus Manivannan Sadhasivam
2020-01-31 22:57 ` Jeffrey Hugo
2020-01-31 13:49 ` [PATCH v2 02/16] bus: mhi: core: Add support for registering MHI controllers Manivannan Sadhasivam
2020-02-06 16:56 ` Greg KH
2020-02-11 19:11 ` Manivannan Sadhasivam
2020-02-11 19:22 ` Greg KH
2020-02-13 15:22 ` Manivannan Sadhasivam
2020-02-06 16:57 ` Greg KH
2020-02-11 18:41 ` Manivannan Sadhasivam
2020-02-11 19:20 ` Greg KH
2020-02-13 15:20 ` Manivannan Sadhasivam
2020-02-13 15:34 ` Greg KH
2020-02-13 15:48 ` Manivannan Sadhasivam
2020-02-13 15:53 ` Greg KH
2020-02-14 16:41 ` Jeffrey Hugo
2020-02-17 5:27 ` Manivannan Sadhasivam
2020-02-17 11:45 ` Greg KH
2020-02-17 11:53 ` Manivannan Sadhasivam
2020-02-17 11:59 ` Greg KH
2020-02-17 13:04 ` Manivannan Sadhasivam
2020-02-17 14:15 ` Greg KH
2020-02-17 16:04 ` Arnd Bergmann
2020-02-17 16:32 ` Greg KH
2020-02-17 17:50 ` Manivannan Sadhasivam
2020-02-06 17:08 ` Jeffrey Hugo
2020-01-31 13:49 ` [PATCH v2 03/16] bus: mhi: core: Add support for registering MHI client drivers Manivannan Sadhasivam
2020-01-31 23:00 ` Jeffrey Hugo
2020-01-31 13:49 ` [PATCH v2 04/16] bus: mhi: core: Add support for creating and destroying MHI devices Manivannan Sadhasivam
2020-02-06 16:16 ` Jeffrey Hugo
2020-01-31 13:49 ` [PATCH v2 05/16] bus: mhi: core: Add support for ringing channel/event ring doorbells Manivannan Sadhasivam
2020-02-06 20:14 ` Jeffrey Hugo
2020-01-31 13:49 ` [PATCH v2 06/16] bus: mhi: core: Add support for PM state transitions Manivannan Sadhasivam
2020-02-06 20:15 ` Jeffrey Hugo
2020-01-31 13:50 ` [PATCH v2 07/16] bus: mhi: core: Add support for basic PM operations Manivannan Sadhasivam
2020-02-06 20:15 ` Jeffrey Hugo
2020-01-31 13:50 ` [PATCH v2 08/16] bus: mhi: core: Add support for downloading firmware over BHIe Manivannan Sadhasivam
2020-02-06 20:15 ` Jeffrey Hugo
2020-01-31 13:50 ` [PATCH v2 09/16] bus: mhi: core: Add support for downloading RDDM image during panic Manivannan Sadhasivam
2020-02-06 16:41 ` Jeffrey Hugo
2020-02-06 20:17 ` Jeffrey Hugo
2020-01-31 13:50 ` [PATCH v2 10/16] bus: mhi: core: Add support for processing events from client device Manivannan Sadhasivam
2020-02-06 20:16 ` Jeffrey Hugo
2020-01-31 13:50 ` [PATCH v2 11/16] bus: mhi: core: Add support for data transfer Manivannan Sadhasivam
2020-02-06 20:16 ` Jeffrey Hugo
2020-02-17 16:13 ` Arnd Bergmann
2020-02-17 16:47 ` Manivannan Sadhasivam
2020-02-18 5:51 ` Manivannan Sadhasivam
2020-02-18 14:34 ` Arnd Bergmann
2020-01-31 13:50 ` [PATCH v2 12/16] bus: mhi: core: Add uevent support for module autoloading Manivannan Sadhasivam
2020-02-06 20:16 ` Jeffrey Hugo
2020-01-31 13:50 ` [PATCH v2 13/16] MAINTAINERS: Add entry for MHI bus Manivannan Sadhasivam
2020-02-03 10:16 ` Andy Shevchenko
2020-02-04 7:05 ` Manivannan Sadhasivam
2020-01-31 13:50 ` [PATCH v2 14/16] net: qrtr: Add MHI transport layer Manivannan Sadhasivam
2020-02-03 18:12 ` Jakub Kicinski
2020-02-04 8:19 ` Manivannan Sadhasivam
2020-02-07 0:14 ` Chris Lew
2020-02-11 3:50 ` Manivannan Sadhasivam
2020-02-12 1:01 ` Chris Lew [this message]
2020-01-31 13:50 ` [PATCH v2 15/16] net: qrtr: Do not depend on ARCH_QCOM Manivannan Sadhasivam
2020-01-31 13:50 ` [PATCH v2 16/16] soc: qcom: Do not depend on ARCH_QCOM for QMI helpers Manivannan Sadhasivam
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=9fbcaa0e-cb94-ba8b-42da-379df3a7a1ce@codeaurora.org \
--to=clew@codeaurora.org \
--cc=arnd@arndb.de \
--cc=bjorn.andersson@linaro.org \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=hemantk@codeaurora.org \
--cc=jhugo@codeaurora.org \
--cc=kuba@kernel.org \
--cc=kvalo@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=smohanad@codeaurora.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
Powered by JetHome