From: Jinlong Mao <quic_jinlmao@quicinc.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>,
Mike Leach <mike.leach@linaro.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
Leo Yan <leo.yan@linaro.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Mao Jinlong <jinlmao@qti.qualcomm.com>,
<coresight@lists.linaro.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
"Tingwei Zhang" <quic_tingweiz@quicinc.com>,
Yuanfang Zhang <quic_yuanfang@quicinc.com>,
Tao Zhang <quic_taozha@quicinc.com>,
Hao Zhang <quic_hazha@quicinc.com>
Subject: Re: [PATCH] coresight: Defer probe when the child dev is not probed
Date: Wed, 2 Mar 2022 16:05:05 +0800 [thread overview]
Message-ID: <c2c45bed-0be1-1942-1267-16f4169c4f67@quicinc.com> (raw)
In-Reply-To: <a1ee270d-8869-2ad2-106c-9d699f457dcd@quicinc.com>
On 3/2/2022 10:29 AM, Jinlong Mao wrote:
>
> On 3/1/2022 11:03 PM, Suzuki K Poulose wrote:
>> Hi
>>
>> On 01/03/2022 13:30, Jinlong Mao wrote:
>>> Hi Mike,
>>>
>>> On 3/1/2022 9:15 PM, Mike Leach wrote:
>>>> Hi,
>>>>
>>>> On Tue, 1 Mar 2022 at 11:42, Jinlong Mao <quic_jinlmao@quicinc.com>
>>>> wrote:
>>>>> On 2/28/2022 10:51 PM, Suzuki K Poulose wrote:
>>>>>
>>
>> ...
>>
>>>>>
>>>>> Hi Suzuki,
>>>>>
>>>>> This issue happens when race condition happens.
>>>>> The condition is that the device and its child_device's probe
>>>>> happens at the same time.
>>>>>
>>>>> For example: device0 and its child device device1.
>>>>> Both of them are calling coresight_register function. device0 is
>>>>> calling coresight_fixup_device_conns.
>>>>> device1 is waiting for device0 to release the coresight_mutex.
>>>>> Because device1's csdev node is allocated,
>>>>> coresight_make_links will be called for device0. Then in
>>>>> coresight_add_sysfs_link, has_conns_grp is true
>>>>> for device0, but has_conns_grp is false for device1 as
>>>>> has_conns_grp is set to true in coresight_create_conns_sysfs_group .
>>>>> The probe of device0 will fail for at this condition.
>>>>>
>>>>>
>>>>> struct coresight_device *coresight_register(struct coresight_desc
>>>>> *desc)
>>>>> {
>>>>> .........
>>>>> mutex_lock(&coresight_mutex);
>>>>>
>>>>> ret = coresight_create_conns_sysfs_group(csdev);
>>>>> if (!ret)
>>>>> ret = coresight_fixup_device_conns(csdev);
>>>>> if (!ret)
>>>>> ret = coresight_fixup_orphan_conns(csdev);
>>>>> if (!ret && cti_assoc_ops && cti_assoc_ops->add)
>>>>> cti_assoc_ops->add(csdev);
>>>>>
>>>>> mutex_unlock(&coresight_mutex);
>>>>>
>>>>> .........
>>>>>
>>>>> }
>>>>>
>>>>> static int coresight_fixup_device_conns(struct coresight_device
>>>>> *csdev)
>>>>> {
>>>>> ..........
>>>>> conn->child_dev =
>>>>> coresight_find_csdev_by_fwnode(conn->child_fwnode);
>>>> The issue appears to be a constraint hidden in the lower layers of
>>>> the code.
>>>> Would a better solution not be to alter the code here:
>>>>
>>>> if (conn->child_dev && conn->child_dev->has_conns_grp) {
>>>> ...
>>>> } else {
>>>> csdev->orphan = true;
>>>> }
>>>>
>>>> which would mean that the connection attempt would drop through to
>>>> label the connection as an orphan, to be cleaned up by the child
>>>> itself when it runs coresight_fixup_orphan_conns()
>>>>
>>
>> Tnanks Mike, I think that is a good solution. Alternatively, we
>> could make sure that device_register() and the fixup following
>> that are atomic.
>>
>> i.e.
>>
>> mutex_lock()
>>
>> device_register()
>> fixup_connections()
>> create_sysfs()
>>
>> mutex_unlock();
>>
>> The fix may be a bit invasive than Mike's proposal, but it makes
>> sure we don't end up with half baked device on the coresight-bus.
>>
>> Suzuki
>
> Thanks Mike & Suzuki.
>
> I will combine your proposals and make the changes.
>
> I will get back to you after the test.
Hi Mike & Suzuki,
Issue is fixed with your proposal.
I submit a new patch "coresight: core: Fix coresight device probe
failure issue".
Please help to review.
Thanks
Jinlong Mao
>
>
> Thanks
> Jinlong Mao
>
prev parent reply other threads:[~2022-03-02 8:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-28 13:31 [PATCH] coresight: Defer probe when the child dev is not probed Mao Jinlong
2022-02-28 14:51 ` Suzuki K Poulose
[not found] ` <a63abe13-793e-323f-e214-1dd9826c8a9a@quicinc.com>
2022-03-01 13:15 ` Mike Leach
2022-03-01 13:30 ` Jinlong Mao
2022-03-01 15:03 ` Suzuki K Poulose
2022-03-02 2:29 ` Jinlong Mao
2022-03-02 8:05 ` Jinlong Mao [this message]
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=c2c45bed-0be1-1942-1267-16f4169c4f67@quicinc.com \
--to=quic_jinlmao@quicinc.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=jinlmao@qti.qualcomm.com \
--cc=leo.yan@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mike.leach@linaro.org \
--cc=quic_hazha@quicinc.com \
--cc=quic_taozha@quicinc.com \
--cc=quic_tingweiz@quicinc.com \
--cc=quic_yuanfang@quicinc.com \
--cc=suzuki.poulose@arm.com \
/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;
as well as URLs for NNTP newsgroup(s).