Message ID | 20220309142206.15632-1-quic_jinlmao@quicinc.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | [v3] coresight: core: Fix coresight device probe failure issue | expand |
Hi Jinlong On 09/03/2022 14:22, Mao Jinlong wrote: > It is possibe that probe failure issue happens when the device > and its child_device's probe happens at the same time. > In coresight_make_links, has_conns_grp is true for parent, but > has_conns_grp is false for child device as has_conns_grp is set > to true in coresight_create_conns_sysfs_group. The probe of parent > device will fail at this condition. Add has_conns_grp check for > child device before make the links and make the process from > device_register to connection_create be atomic to avoid this > probe failure issue. > > Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> > Suggested-by: Mike Leach <mike.leach@linaro.org> > Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com> Thanks for the rework. The patch looks good to me. Suzuki
On 3/10/2022 5:10 PM, Suzuki K Poulose wrote: > Hi Jinlong > > > On 09/03/2022 14:22, Mao Jinlong wrote: >> It is possibe that probe failure issue happens when the device >> and its child_device's probe happens at the same time. >> In coresight_make_links, has_conns_grp is true for parent, but >> has_conns_grp is false for child device as has_conns_grp is set >> to true in coresight_create_conns_sysfs_group. The probe of parent >> device will fail at this condition. Add has_conns_grp check for >> child device before make the links and make the process from >> device_register to connection_create be atomic to avoid this >> probe failure issue. >> >> Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> >> Suggested-by: Mike Leach <mike.leach@linaro.org> >> Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com> > > Thanks for the rework. The patch looks good to me. > > Suzuki Thanks Suzuki. Hi Mathieu & Mike, Could you please help to review and provide your comments for the PATCH V3 ? Thanks Jinlong Mao
On 15/03/2022 08:36, Jinlong Mao wrote: > On 3/10/2022 5:10 PM, Suzuki K Poulose wrote: >> Hi Jinlong >> >> >> On 09/03/2022 14:22, Mao Jinlong wrote: >>> It is possibe that probe failure issue happens when the device >>> and its child_device's probe happens at the same time. >>> In coresight_make_links, has_conns_grp is true for parent, but >>> has_conns_grp is false for child device as has_conns_grp is set >>> to true in coresight_create_conns_sysfs_group. The probe of parent >>> device will fail at this condition. Add has_conns_grp check for >>> child device before make the links and make the process from >>> device_register to connection_create be atomic to avoid this >>> probe failure issue. >>> >>> Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> >>> Suggested-by: Mike Leach <mike.leach@linaro.org> >>> Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com> >> >> Thanks for the rework. The patch looks good to me. >> >> Suzuki > Thanks Suzuki. > > Hi Mathieu & Mike, > > Could you please help to review and provide your comments for the PATCH > V3 ? Thats what I just said above. The patch looks good to me, I can queue this in the next cycle. Kind regards Suzuki > > Thanks > Jinlong Mao
On 3/15/2022 4:42 PM, Suzuki K Poulose wrote: > On 15/03/2022 08:36, Jinlong Mao wrote: >> On 3/10/2022 5:10 PM, Suzuki K Poulose wrote: >>> Hi Jinlong >>> >>> >>> On 09/03/2022 14:22, Mao Jinlong wrote: >>>> It is possibe that probe failure issue happens when the device >>>> and its child_device's probe happens at the same time. >>>> In coresight_make_links, has_conns_grp is true for parent, but >>>> has_conns_grp is false for child device as has_conns_grp is set >>>> to true in coresight_create_conns_sysfs_group. The probe of parent >>>> device will fail at this condition. Add has_conns_grp check for >>>> child device before make the links and make the process from >>>> device_register to connection_create be atomic to avoid this >>>> probe failure issue. >>>> >>>> Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> >>>> Suggested-by: Mike Leach <mike.leach@linaro.org> >>>> Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com> >>> >>> Thanks for the rework. The patch looks good to me. >>> >>> Suzuki >> Thanks Suzuki. >> >> Hi Mathieu & Mike, >> >> Could you please help to review and provide your comments for the >> PATCH V3 ? > > Thats what I just said above. The patch looks good to me, I can queue > this in the next cycle. Thanks Suzuki. Best Regards Jinlong Mao > > Kind regards > Suzuki > >> >> Thanks >> Jinlong Mao >
On 15/03/2022 08:52, Jinlong Mao wrote: > > On 3/15/2022 4:42 PM, Suzuki K Poulose wrote: >> On 15/03/2022 08:36, Jinlong Mao wrote: >>> On 3/10/2022 5:10 PM, Suzuki K Poulose wrote: >>>> Hi Jinlong >>>> >>>> >>>> On 09/03/2022 14:22, Mao Jinlong wrote: >>>>> It is possibe that probe failure issue happens when the device >>>>> and its child_device's probe happens at the same time. >>>>> In coresight_make_links, has_conns_grp is true for parent, but >>>>> has_conns_grp is false for child device as has_conns_grp is set >>>>> to true in coresight_create_conns_sysfs_group. The probe of parent >>>>> device will fail at this condition. Add has_conns_grp check for >>>>> child device before make the links and make the process from >>>>> device_register to connection_create be atomic to avoid this >>>>> probe failure issue. >>>>> >>>>> Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> >>>>> Suggested-by: Mike Leach <mike.leach@linaro.org> >>>>> Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com> >>>> >>>> Thanks for the rework. The patch looks good to me. >>>> >>>> Suzuki >>> Thanks Suzuki. >>> >>> Hi Mathieu & Mike, >>> >>> Could you please help to review and provide your comments for the >>> PATCH V3 ? >> >> Thats what I just said above. The patch looks good to me, I can queue >> this in the next cycle. Queued here: https://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git/commit/?h=next&id=8c1d3f79d9ca48e406b78e90e94cf09a8c076bf2 Cheers Suzuki
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index 88653d1c06a4..7fed6e9c0ca1 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1382,7 +1382,7 @@ static int coresight_fixup_device_conns(struct coresight_device *csdev) continue; conn->child_dev = coresight_find_csdev_by_fwnode(conn->child_fwnode); - if (conn->child_dev) { + if (conn->child_dev && conn->child_dev->has_conns_grp) { ret = coresight_make_links(csdev, conn, conn->child_dev); if (ret) @@ -1574,6 +1574,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) int nr_refcnts = 1; atomic_t *refcnts = NULL; struct coresight_device *csdev; + bool registered = false; csdev = kzalloc(sizeof(*csdev), GFP_KERNEL); if (!csdev) { @@ -1594,7 +1595,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) refcnts = kcalloc(nr_refcnts, sizeof(*refcnts), GFP_KERNEL); if (!refcnts) { ret = -ENOMEM; - goto err_free_csdev; + kfree(csdev); + goto err_out; } csdev->refcnt = refcnts; @@ -1619,6 +1621,13 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev)); dev_set_name(&csdev->dev, "%s", desc->name); + /* + * Make sure the device registration and the connection fixup + * are synchronised, so that we don't see uninitialised devices + * on the coresight bus while trying to resolve the connections. + */ + mutex_lock(&coresight_mutex); + ret = device_register(&csdev->dev); if (ret) { put_device(&csdev->dev); @@ -1626,7 +1635,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) * All resources are free'd explicitly via * coresight_device_release(), triggered from put_device(). */ - goto err_out; + goto out_unlock; } if (csdev->type == CORESIGHT_DEV_TYPE_SINK || @@ -1641,11 +1650,11 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) * from put_device(), which is in turn called from * function device_unregister(). */ - goto err_out; + goto out_unlock; } } - - mutex_lock(&coresight_mutex); + /* Device is now registered */ + registered = true; ret = coresight_create_conns_sysfs_group(csdev); if (!ret) @@ -1655,16 +1664,18 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) if (!ret && cti_assoc_ops && cti_assoc_ops->add) cti_assoc_ops->add(csdev); +out_unlock: mutex_unlock(&coresight_mutex); - if (ret) { + /* Success */ + if (!ret) + return csdev; + + /* Unregister the device if needed */ + if (registered) { coresight_unregister(csdev); return ERR_PTR(ret); } - return csdev; - -err_free_csdev: - kfree(csdev); err_out: /* Cleanup the connection information */ coresight_release_platform_data(NULL, desc->pdata);
It is possibe that probe failure issue happens when the device and its child_device's probe happens at the same time. In coresight_make_links, has_conns_grp is true for parent, but has_conns_grp is false for child device as has_conns_grp is set to true in coresight_create_conns_sysfs_group. The probe of parent device will fail at this condition. Add has_conns_grp check for child device before make the links and make the process from device_register to connection_create be atomic to avoid this probe failure issue. Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> Suggested-by: Mike Leach <mike.leach@linaro.org> Signed-off-by: Mao Jinlong <quic_jinlmao@quicinc.com> --- drivers/hwtracing/coresight/coresight-core.c | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-)