Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4805372rdb; Tue, 12 Dec 2023 09:44:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjEzAtbA2o4X4bbnXrHnIntvO8PTS4qoIM3lPKglGdmuFyKfPZwMZ4WLr8kpbQmXj74Kns X-Received: by 2002:a05:6a20:1047:b0:190:fca:72d8 with SMTP id gt7-20020a056a20104700b001900fca72d8mr7409866pzc.109.1702403070506; Tue, 12 Dec 2023 09:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702403070; cv=none; d=google.com; s=arc-20160816; b=h6Ta03H93EIWQ2c3ZRl0CWH5qyX1tZ2NvCi77LW3/hDyGL/lq1yUpnFUsvRbxao5nG He3OStNH8rXeuw86eEOVtJoIBD7KesyX8oLNqoB5F9Rxa/liPGvF3yqWZD5+YtxT/uzh zKV2B7QM/28BhhEpxzPCOl6JoWIqDh9grgrzKb/gkVVnotsn+dJmpzsqy//C/AxWyF9i RGfv4hp333VFa+IpAzrhn3U2T9YwWvCQS8AZ/2oawqPKfQ4AyqWfmsefMoc5No48MC2+ yruRDZvrSEkceqiBHxNkxGe53jlyXW+C5arlC+baO6ADCez2mrAPlTLDsbQfXyzpuJGK NM7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=LyB/hUCUxMLSFlaUsuFNBayqJaIJMITtc0Qxhk9IRAE=; fh=TzxcpWgMr0ZHRVWWO//RG91rk/VEV7I73tOUOq+KfKQ=; b=ks080LDPkA2NFPLyaWktEaeC9Dak5vOwPxtpNhzMy2kHv1oOY//fEWRJ7ZvKBoryS5 0MFouiPRM/aOGmby38Mkz9k2bcyT0V1+kLwAg2kIYFcGOwDFT6SQ8iG0gSLY+yGldhh0 ZUhlc/P+rzMhwWvqWA7Qwal6f5I/8x5/rATyuSN3GCh2Ira1iO6EMVowDCeWwouyQJYG s9oFuFjcxaJ415pIlhni7u8kXfwuq5pYvarj+5FW/sdk6mN8tzwRbu3P4KrZ/z/Jn0jr WQvq6+9ZthkdxTgARRFJUUE9mHHZEYZts5QSHofdpQXIufbNuLbhKBvVHOD4C0dlIGUu jVQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c17-20020a631c51000000b005b16e351343si8154086pgm.241.2023.12.12.09.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:44:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D8087805E515; Tue, 12 Dec 2023 09:44:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376901AbjLLRoM (ORCPT + 99 others); Tue, 12 Dec 2023 12:44:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232817AbjLLRoL (ORCPT ); Tue, 12 Dec 2023 12:44:11 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B563283 for ; Tue, 12 Dec 2023 09:44:17 -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 938D9FEC; Tue, 12 Dec 2023 09:45:03 -0800 (PST) Received: from [10.57.41.249] (unknown [10.57.41.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0E0313F762; Tue, 12 Dec 2023 09:44:15 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 17:44:14 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/8] coresight: Fix issue where a source device's helpers aren't disabled Content-Language: en-GB To: James Clark , coresight@lists.linaro.org Cc: Mike Leach , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com References: <20231212155407.1429121-1-james.clark@arm.com> <20231212155407.1429121-2-james.clark@arm.com> From: Suzuki K Poulose In-Reply-To: <20231212155407.1429121-2-james.clark@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 09:44:28 -0800 (PST) Hi James On 12/12/2023 15:53, James Clark wrote: > The linked commit reverts the change that accidentally used some sysfs > enable/disable functions from Perf which broke the refcounting, but it > also removes the fact that the sysfs disable function disabled the > helpers. > > Add a new wrapper function that does both which is used by both Perf and > sysfs, and label the sysfs disable function appropriately. The naming of > all of the functions will be tidied up later to avoid this happening > again. > > Fixes: 287e82cf69aa ("coresight: Fix crash when Perf and sysfs modes are used concurrently") But we still don't "enable" the helpers from perf mode with this patch. i.e., we use source_ops()->enable directly. So, I guess this patch doesn't fix a bug as such. But that said, it would be good to enable/disable helpers for sources, in perf mode. Suzuki > Signed-off-by: James Clark > --- > drivers/hwtracing/coresight/coresight-core.c | 30 ++++++++++++++----- > .../hwtracing/coresight/coresight-etm-perf.c | 2 +- > drivers/hwtracing/coresight/coresight-priv.h | 2 +- > 3 files changed, 25 insertions(+), 9 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c > index d7f0e231feb9..965bb6d4e1bf 100644 > --- a/drivers/hwtracing/coresight/coresight-core.c > +++ b/drivers/hwtracing/coresight/coresight-core.c > @@ -441,8 +441,26 @@ static void coresight_disable_helpers(struct coresight_device *csdev) > } > } > > +/* > + * Helper function to call source_ops(csdev)->disable and also disable the > + * helpers. > + * > + * There is an imbalance between coresight_enable_path() and > + * coresight_disable_path(). Enabling also enables the source's helpers as part > + * of the path, but disabling always skips the first item in the path (which is > + * the source), so sources and their helpers don't get disabled as part of that > + * function and we need the extra step here. > + */ > +void coresight_disable_source(struct coresight_device *csdev, void *data) > +{ > + if (source_ops(csdev)->disable) > + source_ops(csdev)->disable(csdev, data); > + coresight_disable_helpers(csdev); > +} > +EXPORT_SYMBOL_GPL(coresight_disable_source); > + > /** > - * coresight_disable_source - Drop the reference count by 1 and disable > + * coresight_disable_source_sysfs - Drop the reference count by 1 and disable > * the device if there are no users left. > * > * @csdev: The coresight device to disable > @@ -451,17 +469,15 @@ static void coresight_disable_helpers(struct coresight_device *csdev) > * > * Returns true if the device has been disabled. > */ > -bool coresight_disable_source(struct coresight_device *csdev, void *data) > +static bool coresight_disable_source_sysfs(struct coresight_device *csdev, > + void *data) > { > if (atomic_dec_return(&csdev->refcnt) == 0) { > - if (source_ops(csdev)->disable) > - source_ops(csdev)->disable(csdev, data); > - coresight_disable_helpers(csdev); > + coresight_disable_source(csdev, data); > csdev->enable = false; > } > return !csdev->enable; > } > -EXPORT_SYMBOL_GPL(coresight_disable_source); > > /* > * coresight_disable_path_from : Disable components in the given path beyond > @@ -1204,7 +1220,7 @@ void coresight_disable(struct coresight_device *csdev) > if (ret) > goto out; > > - if (!csdev->enable || !coresight_disable_source(csdev, NULL)) > + if (!csdev->enable || !coresight_disable_source_sysfs(csdev, NULL)) > goto out; > > switch (csdev->subtype.source_subtype) { > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c > index a52cfcce25d6..c0c60e6a1703 100644 > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c > @@ -589,7 +589,7 @@ static void etm_event_stop(struct perf_event *event, int mode) > return; > > /* stop tracer */ > - source_ops(csdev)->disable(csdev, event); > + coresight_disable_source(csdev, event); Does this result i > > /* tell the core */ > event->hw.state = PERF_HES_STOPPED; > diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h > index 767076e07970..30c051055e54 100644 > --- a/drivers/hwtracing/coresight/coresight-priv.h > +++ b/drivers/hwtracing/coresight/coresight-priv.h > @@ -233,6 +233,6 @@ void coresight_set_percpu_sink(int cpu, struct coresight_device *csdev); > struct coresight_device *coresight_get_percpu_sink(int cpu); > int coresight_enable_source(struct coresight_device *csdev, enum cs_mode mode, > void *data); > -bool coresight_disable_source(struct coresight_device *csdev, void *data); > +void coresight_disable_source(struct coresight_device *csdev, void *data); > > #endif