From patchwork Wed Mar 8 17:38:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 6317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp490329wrd; Wed, 8 Mar 2023 10:15:36 -0800 (PST) X-Google-Smtp-Source: AK7set/RH4440ErLW/UUk2zsWIxQpqHMYpUIjVPzjKuBRclN84MPNNlu4IxJIZ/bWIpUR7B0wNqE X-Received: by 2002:a17:903:230e:b0:198:fca8:2108 with SMTP id d14-20020a170903230e00b00198fca82108mr23162826plh.44.1678299336720; Wed, 08 Mar 2023 10:15:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678299336; cv=none; d=google.com; s=arc-20160816; b=A5cSOzSY3tCuZOcmBviOmeXRTqJeU+FRgYLTKXIG8mmf9UPtw3HMYn4ZmqFobsVb4g sts/lytvT+vWVoS2xlJlw0xXexSILQn96PTcmXslvifRJ2XN7Oy7VqrOmwKIq7NcYqU9 5phSJ0tXV+hOfp/QlhgvHNK89a9Q9MrYJ8dmHAtNyr9M6bPV92QrEH/57JCoDcbIm+Hz F59xqyTQhw2w5gq0wVCYel6S4Xaj8VSPOz3AtynMr1NQTSpflxS/1GEOWSf9T4slMWzw IcV8A/SELhz+URq6mHGxL49zKLt4twthmsry1cKk2Wi5AEjAroGc1X1X0Toc+Q2gmvr1 dHgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ml4SFcq+WDHvaNX98kzKqYLD6nG85uC7EoNUZv+HIsw=; b=TquwygG+5gs1vXznnqIBL3ddRRQ8Nj5JB0hFo4Ip5TeGm1qH9/S7DNrMnA+xjJi9zB S6+IoF/P8u372zV1poAVVoBt14wXJg+D6hKjwXDS9sJBzkS7n4eem2Ag2Qx4EP7ec0h8 aa4pdQFuMg0o9+4nkWpq1USFX2nVCnolxV5f4g3azobf4k9HOrzpn2Tvppv6SoqrOiQ5 hK4VbtbllRhuiqH0XoEa9SnCvSepxZhvtgQSBoEmWEL07GTj2281nZ8Id0fWs/T3eOUK hy5QqbT4bZkZvrBm80ILbNyjE81suBrsEJ9C9q4wF6Ly5Vx34VjYhL2efOxMMO34MqnR /GrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a170902d50c00b001992144f3aasi17540724plg.581.2023.03.08.10.15.23; Wed, 08 Mar 2023 10:15:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbjCHRjR (ORCPT + 99 others); Wed, 8 Mar 2023 12:39:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjCHRjN (ORCPT ); Wed, 8 Mar 2023 12:39:13 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9ADD412F13 for ; Wed, 8 Mar 2023 09:39:11 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 97C8D1063; Wed, 8 Mar 2023 09:39:54 -0800 (PST) Received: from e127643.arm.com (unknown [10.57.48.148]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9C8443F67D; Wed, 8 Mar 2023 09:39:09 -0800 (PST) From: James Clark To: coresight@lists.linaro.org Cc: James Clark , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , Alexander Shishkin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/8] coresight: Fix CTI module refcount leak by making it a helper device Date: Wed, 8 Mar 2023 17:38:54 +0000 Message-Id: <20230308173904.3449231-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759823293876726706?= X-GMAIL-MSGID: =?utf-8?q?1759824404775045448?= Currently there is a refcount leak in CTI when using system wide mode or tracing multithreaded applications. See the last commit for a reproducer. This prevents the module from being unloaded. Historically there have been a few issues and fixes attempted around here which have resulted in some extra logic and a member to keep track of CTI being enabled 'struct coresight_device->ect_enabled'. The fix in commit 665c157e0204 ("coresight: cti: Fix hang in cti_disable_hw()") was also related to CTI having its own enable/disable path which came later than other devices. If we make CTI a helper device and enable helper devices adjacent to the path we get very similar enable/disable behavior to now, but with more reuse of the existing reference counting logic in the coresight core code. This also affects CATU which can have a little bit of its hard coded enable/disable code removed. Enabling CATU on the generic path does require that input connections are tracked so that it can get its associated ETR buffer. Applies to coresight/next (669c4614236a7) but also requires the realloc_array patch here [1]. Also available in full here [2]. [1]: https://lore.kernel.org/linux-arm-kernel/20230306152723.3090195-1-james.clark@arm.com/ [2]: https://gitlab.arm.com/linux-arm/linux-jc/-/tree/james-cs-cti-module-refcount-fix-v1 James Clark (8): coresight: Use enum type for cs_mode wherever possible coresight: Change name of pdata->conns coresight: Rename nr_outports to nr_outconns coresight: Dynamically add connections coresight: Store in-connections as well as out-connections coresight: Refactor out buffer allocation function for ETR coresight: Enable and disable helper devices adjacent to the path coresight: Fix CTI module refcount leak by making it a helper device drivers/hwtracing/coresight/coresight-catu.c | 34 ++- drivers/hwtracing/coresight/coresight-core.c | 258 +++++++++++------- .../hwtracing/coresight/coresight-cti-core.c | 56 ++-- .../hwtracing/coresight/coresight-cti-sysfs.c | 4 +- drivers/hwtracing/coresight/coresight-cti.h | 4 +- drivers/hwtracing/coresight/coresight-etb10.c | 3 +- .../coresight/coresight-etm3x-core.c | 6 +- .../coresight/coresight-etm4x-core.c | 6 +- .../hwtracing/coresight/coresight-platform.c | 168 +++++++++--- drivers/hwtracing/coresight/coresight-priv.h | 9 +- drivers/hwtracing/coresight/coresight-stm.c | 6 +- drivers/hwtracing/coresight/coresight-sysfs.c | 1 - .../hwtracing/coresight/coresight-tmc-etf.c | 2 +- .../hwtracing/coresight/coresight-tmc-etr.c | 88 +++--- drivers/hwtracing/coresight/coresight-tmc.h | 2 + drivers/hwtracing/coresight/coresight-tpdm.c | 4 +- drivers/hwtracing/coresight/coresight-tpiu.c | 3 +- drivers/hwtracing/coresight/coresight-trbe.c | 3 +- drivers/hwtracing/coresight/ultrasoc-smb.c | 3 +- drivers/hwtracing/coresight/ultrasoc-smb.h | 2 +- include/linux/coresight.h | 92 ++++--- 21 files changed, 483 insertions(+), 271 deletions(-)