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=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 CA384C433E1 for ; Tue, 14 Jul 2020 01:12:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FC9D2186A for ; Tue, 14 Jul 2020 01:12:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dxOF3GJ5"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="gmsqAvZC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FC9D2186A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UBmwpWbqfhato1pUfbb/++iewl8KfCyJOd1WHRn7JfM=; b=dxOF3GJ5T++fmxW/nSYiNWMvZ nxNWpvOfqHZkgWcfPEmJbvOMXf5CWB3X03BiEdS6c7LKbSqNcveN/LOq0JJsdaSITohBOuuqU2mfA E2IrPsDNY0t2cJUtG/vFkPHy4gSz1OCpVToFBILA9zFMHh17uSdFbJVXfI3kHMGydb6hvzv9ijbNX GoKON7bGi1bBJMN7EZJ7r6yhMRWbxXGZD/M3cou9wzGXIytIOADzINsMlqpLEcH+x2NQjOrgyJhFR hiTqXjGry4+yr/pDWDVzLJt1GcRn3Ngfilb69ryEH4cAxYawCI2AAJpJ/KjpfaNseHHJrOePPqJCq ZtimA9L5w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jv9So-00053f-Dz; Tue, 14 Jul 2020 01:10:30 +0000 Received: from m43-7.mailgun.net ([69.72.43.7]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jv9Sj-00052Y-2W for linux-arm-kernel@lists.infradead.org; Tue, 14 Jul 2020 01:10:26 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1594689024; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=6K6VyYymFberSSJcBNIl7vNUnhtNTtFv2YirakJwqhw=; b=gmsqAvZCcgJdbukh0l78osGLpeDMAHZEMw4wVqzWg5he7RiyCBDyxQutb0xdHL43kmIRxJdV pa0kdLWr1iUQAnr2sg5bLygASMqWnzJDyUx2Bdo1HRJb/OyIQeX5fDSy1Yd0ygRA8ccOqI/Q E1s7MNlbWOnL4FltGHckLO+71Yw= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyJiYzAxZiIsICJsaW51eC1hcm0ta2VybmVsQGxpc3RzLmluZnJhZGVhZC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n05.prod.us-east-1.postgun.com with SMTP id 5f0d05ff8423214e13a67d0c (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 14 Jul 2020 01:10:23 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 7220DC433CB; Tue, 14 Jul 2020 01:10:22 +0000 (UTC) Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: tingwei) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1ACFAC433CA; Tue, 14 Jul 2020 01:10:20 +0000 (UTC) MIME-Version: 1.0 Date: Tue, 14 Jul 2020 09:10:20 +0800 From: tingwei@codeaurora.org To: Mathieu Poirier Subject: Re: [PATCH v1 19/21] coresight: disable trace path with device being removed In-Reply-To: <20200713221123.GA1277971@xps15> References: <20200701071427.10477-1-tingwei@codeaurora.org> <20200701071427.10477-20-tingwei@codeaurora.org> <20200713221123.GA1277971@xps15> Message-ID: X-Sender: tingwei@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200713_211025_251160_13B1AA83 X-CRM114-Status: GOOD ( 32.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tsoni@codeaurora.org, Sai Prakash Ranjan , Kim Phillips , Suzuki K Poulose , Alexander Shishkin , Greg Kroah-Hartman , coresight@lists.linaro.org, Mao Jinlong , Mian Yousaf Kaukab , Russell King , Randy Dunlap , Leo Yan , linux-arm-kernel , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Thanks for reviewing this, Mathieu. On 2020-07-14 06:11, Mathieu Poirier wrote: > Good day Tingwei, > > On Wed, Jul 01, 2020 at 03:14:25PM +0800, Tingwei Zhang wrote: >> Coresight trace path holds the reference to devices on the path. >> Disable trace path before really remove coresight device. >> >> Signed-off-by: Tingwei Zhang >> --- >> drivers/hwtracing/coresight/coresight.c | 137 >> ++++++++++++++++++++++++ >> 1 file changed, 137 insertions(+) >> >> diff --git a/drivers/hwtracing/coresight/coresight.c > b/drivers/hwtracing/coresight/coresight.c >> index cf7079f4b99c..0870316ec4c4 100644 >> --- a/drivers/hwtracing/coresight/coresight.c >> +++ b/drivers/hwtracing/coresight/coresight.c >> @@ -490,6 +490,138 @@ void coresight_disable_path(struct list_head > *path) >> } >> EXPORT_SYMBOL_GPL(coresight_disable_path); >> >> +/* >> + * coresight_dev_on_path - Check if device is on trace path. >> + * >> + * @path - The trace path to check with. >> + * @csdev - The coresight device to check >> + * >> + * Returns true if the device is on trace path. >> + */ >> +bool coresight_dev_on_path(struct list_head *path, >> + struct coresight_device *csdev) >> +{ >> + struct coresight_node *nd; >> + >> + list_for_each_entry(nd, path, link) { >> + if (csdev == nd->csdev) >> + return true; >> + } >> + return false; >> +} >> + >> +/* >> + * coresight_disable_path_with - Disable trace path >> + * if trace path has concerned device on it. >> + * >> + * @path - The trace path to check. >> + * @csdev - Concerned coresight device >> + * >> + * Returns true if the device is on trace path. >> + */ >> +static bool coresight_disable_path_with(struct list_head *path, >> + struct coresight_device *csdev) >> +{ >> + struct coresight_node *src_nd; >> + struct coresight_device *srcdev; >> + bool ret; >> + >> + ret = coresight_dev_on_path(path, csdev); >> + if (ret) { >> + src_nd = list_first_entry(path, struct coresight_node, > link); >> + srcdev = src_nd->csdev; >> + if (source_ops(srcdev)->disable) >> + source_ops(srcdev)->disable(srcdev, NULL); >> + srcdev->enable = false; >> + coresight_disable_path(path); >> + coresight_release_path(path); >> + } >> + >> + return ret; >> +} >> + >> +/* >> + * __coresight_disable_with - Check cpu trace path and >> + * stm trace path. Disable any path with conerned device. >> + * >> + * @csdev - Concerned coresight device >> + * >> + */ >> +static void __coresight_disable_with(struct coresight_device *csdev) >> +{ >> + int cpu; >> + struct list_head *path = NULL; >> + >> + for_each_possible_cpu(cpu) { >> + path = per_cpu(tracer_path, cpu); >> + if (path) { >> + if (coresight_disable_path_with(path, csdev)) >> + per_cpu(tracer_path, cpu) = NULL; >> + } >> + } >> + if (stm_path) { >> + path = stm_path; >> + if (coresight_disable_path_with(path, csdev)) >> + stm_path = NULL; >> + } >> +} >> + >> +static int coresight_disable_match(struct device *dev, void *data) >> +{ >> + int i; >> + struct coresight_device *csdev, *iterator; >> + struct coresight_connection *conn; >> + >> + csdev = data; >> + iterator = to_coresight_device(dev); >> + >> + /* No need to check oneself */ >> + if (csdev == iterator) >> + return 0; >> + >> + /* >> + * Circle throuch all the connection of that component. If we > find >> + * a connection whose name matches @csdev, disable path with it. >> + */ >> + for (i = 0; i < iterator->pdata->nr_outport; i++) { >> + conn = &iterator->pdata->conns[i]; >> + >> + if (conn->child_dev == NULL) >> + continue; >> + >> + if (csdev->dev.fwnode == conn->child_fwnode) { >> + __coresight_disable_with(iterator); >> + >> + /* No need to continue */ >> + break; >> + } >> + } >> + >> + /* >> + * Returning '0' ensures that all known components on the >> + * bus will be checked. >> + */ >> + return 0; >> +} >> + >> +/** >> + * coresight_disable_with - disable any path with @csdev. >> + * @csdev: The device to check. >> + * >> + * Search for all the active paths. If @csdev is part of that path, >> + * disable the whole path. Device with CORESIGHT_DEV_TYPE_HELPER type >> + * is not part of path. Search for its parent device and disable any >> + * path with that device. >> + */ >> +void coresight_disable_with(struct coresight_device *csdev) >> +{ >> + if (csdev->type != CORESIGHT_DEV_TYPE_HELPER) >> + return __coresight_disable_with(csdev); > > The main problem is indeed to take care of ongoing sessions which, > other > than the > module mechanic, is the bulk of the code added in this set. > > I've been thinking about this problem while reviewing an unrelated > patchset and > the solution I see is to let the driver core work for us. Since there > is > no > implicit relation between modules, all we need is to introduce one > using > try_module_get() and module_put(). The module for each csdev can be > accessed > via csdev->dev->parent->driver->module. > > From looking at the code if we call try_module_get() in > coresight_grab_device() > and module_put() in coresight_drop_device(), the driver core won't let > users > remove modules for as long as a session is using the driver. That way > all > you > need is the loop below and that is quite simple. > > Let me know what you think, > Mathieu I agree with you, Mathieu. Using try_module_get() and module_put() is a simpler, cleaner and safer way. I'll make the change, verify them and send a new patch set for review. Tingwei > >> + if (csdev->pdata->nr_inport) >> + bus_for_each_dev(&coresight_bustype, NULL, >> + csdev, coresight_disable_match); >> +} >> + >> int coresight_enable_path(struct list_head *path, u32 mode, void > *sink_data) >> { >> >> @@ -1243,6 +1375,7 @@ void coresight_release_platform_data(struct > coresight_platform_data *pdata) >> >> for (i = 0; i < pdata->nr_outport; i++) { >> if (pdata->conns[i].child_fwnode) { >> + pdata->conns[i].child_dev = NULL; >> fwnode_handle_put(pdata->conns[i].child_fwnode); >> pdata->conns[i].child_fwnode = NULL; >> } >> @@ -1349,9 +1482,13 @@ EXPORT_SYMBOL_GPL(coresight_register); >> void coresight_unregister(struct coresight_device *csdev) >> { >> etm_perf_del_symlink_sink(csdev); >> + >> + mutex_lock(&coresight_mutex); >> + coresight_disable_with(csdev); >> /* Remove references of that device in the topology */ >> coresight_remove_conns(csdev); >> coresight_release_platform_data(csdev->pdata); >> + mutex_unlock(&coresight_mutex); >> device_unregister(&csdev->dev); >> } >> EXPORT_SYMBOL_GPL(coresight_unregister); >> -- >> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora > Forum, >> a Linux Foundation Collaborative Project >> > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel