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=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,USER_AGENT_GIT autolearn=ham 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 0A20DC433DF for ; Wed, 1 Jul 2020 07:20:36 +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 B8A32206BE for ; Wed, 1 Jul 2020 07:20:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="05MnwhBV"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="C+sl+2Xn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8A32206BE 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-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hYJa7zRLG9l0Wz9dheOHLpIOdcJdVf/DNxyykdO6joE=; b=05MnwhBVe3EXQD1Admka/QaDr axnVJZbgARjPkqfSH7vqhjrGuzQcF7zMDZK0uxM06w5jcTSh9y9qUOpgXQt8dDkO2Gs9zymvq5CFv 28u0K2o+uFw14Butw5aA24qtgmCUxdnO92ecbjQ4mn2thFfSmbZcFwLSJNq0VnmrlSxaDn9d2AdUX +wZF9GD0BtifK0CbaLuQMkLdLtWz+tCugPjWSgU4+YtdousD03WV2hQsnSHRyZU9mq7Nh6+Hw+xAL HD8jg3cum7vpbKXfku5OUW1we5I3PY274nvZtgM6Cuhwr/m4lvtrd3cLTGIUB0O+n4UgQTzu9vd0V OtSfPNlzg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqX0Y-0002sT-Ik; Wed, 01 Jul 2020 07:18:14 +0000 Received: from mail29.static.mailgun.info ([104.130.122.29]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqWyy-00016u-4E for linux-arm-kernel@lists.infradead.org; Wed, 01 Jul 2020 07:16:43 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1593587799; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=SZtJPutjVvQ9wwaxCgF+Jv7OklnVN8t/EDEZUKgwye0=; b=C+sl+2XnfKDdVHC5tqPdtPnQeNjsf0rsEcBtn5wxbym6gMs28JLSRp5wkzW2i5EWiXB66mYa QQSLpjh6+dnqB2UVHOVaRYOhzKXiB2aQb7L7qI7lMkGpuy4CXQVoo7qH9sxGperfUjqoOVWw Yk34ehubUWMgsH/QB0ln/PG7fZg= X-Mailgun-Sending-Ip: 104.130.122.29 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-n07.prod.us-east-1.postgun.com with SMTP id 5efc3849c4bb4f886de7801e (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 01 Jul 2020 07:16:25 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DEA2DC433CB; Wed, 1 Jul 2020 07:16:24 +0000 (UTC) Received: from tingweiz-gv.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: tingwei) by smtp.codeaurora.org (Postfix) with ESMTPSA id 546A2C433A1; Wed, 1 Jul 2020 07:16:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 546A2C433A1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=tingwei@codeaurora.org From: Tingwei Zhang To: Mathieu Poirier , Suzuki K Poulose Subject: [PATCH v1 19/21] coresight: disable trace path with device being removed Date: Wed, 1 Jul 2020 15:14:25 +0800 Message-Id: <20200701071427.10477-20-tingwei@codeaurora.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20200701071427.10477-1-tingwei@codeaurora.org> References: <20200701071427.10477-1-tingwei@codeaurora.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200701_031639_769509_242560F8 X-CRM114-Status: GOOD ( 20.15 ) 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 , Mao Jinlong , Alexander Shishkin , Greg Kroah-Hartman , coresight@lists.linaro.org, Randy Dunlap , Mian Yousaf Kaukab , Russell King , Tingwei Zhang , Leo Yan , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); + 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