mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: James Clark <james.clark@arm.com>,
	coresight@lists.linaro.org, quic_jinlmao@quicinc.com,
	mike.leach@linaro.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
	Leo Yan <leo.yan@linaro.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 13/13] coresight: Fix CTI module refcount leak by making it a helper device
Date: Mon, 24 Apr 2023 14:22:59 +0100	[thread overview]
Message-ID: <7dab2287-97ce-7603-9b9e-445135758d09@arm.com> (raw)
In-Reply-To: <2c6cbccb-44e9-edaf-f1a1-ac9c5175537f@arm.com>

On 24/04/2023 12:09, James Clark wrote:
> 
> 
> On 24/04/2023 11:43, Suzuki K Poulose wrote:
>> On 04/04/2023 16:51, James Clark wrote:
>>> The CTI module has some hard coded refcounting code that has a leak.
>>> For example running perf and then trying to unload it fails:
>>>
>>>     perf record -e cs_etm// -a -- ls
>>>     rmmod coresight_cti
>>>
>>>     rmmod: ERROR: Module coresight_cti is in use
>>>
>>> The coresight core already handles references of devices in use, so by
>>> making CTI a normal helper device, we get working refcounting for free.
>>>
>>> Signed-off-by: James Clark <james.clark@arm.com>
>>> ---
>>>    drivers/hwtracing/coresight/coresight-core.c  | 104 ++++++------------
>>>    .../hwtracing/coresight/coresight-cti-core.c  |  52 +++++----
>>>    .../hwtracing/coresight/coresight-cti-sysfs.c |   4 +-
>>>    drivers/hwtracing/coresight/coresight-cti.h   |   4 +-
>>>    drivers/hwtracing/coresight/coresight-priv.h  |   4 +-
>>>    drivers/hwtracing/coresight/coresight-sysfs.c |   4 +
>>>    include/linux/coresight.h                     |  30 +----
>>>    7 files changed, 75 insertions(+), 127 deletions(-)
>>>
>>> diff --git a/drivers/hwtracing/coresight/coresight-core.c
>>> b/drivers/hwtracing/coresight/coresight-core.c
>>> index 16689fe4ba98..2af416bba983 100644
>>> --- a/drivers/hwtracing/coresight/coresight-core.c
>>> +++ b/drivers/hwtracing/coresight/coresight-core.c
>>> @@ -236,60 +236,44 @@ void coresight_disclaim_device(struct
>>> coresight_device *csdev)
>>>    }
>>>    EXPORT_SYMBOL_GPL(coresight_disclaim_device);
>>>    -/* enable or disable an associated CTI device of the supplied CS
>>> device */
>>> -static int
>>> -coresight_control_assoc_ectdev(struct coresight_device *csdev, bool
>>> enable)
>>> +/*
>>> + * Add a helper as an output device. This function takes the
>>> @coresight_mutex
>>> + * because it's assumed that it's called from the helper device,
>>> outside of the
>>> + * core code where the mutex would already be held. Don't add new
>>> calls to this
>>> + * from inside the core code, instead try to add the new helper to
>>> the DT and
>>> + * ACPI where it will be picked up and linked automatically.
>>> + */
>>> +void coresight_add_helper(struct coresight_device *csdev,
>>> +              struct coresight_device *helper)
>>>    {
>>> -    int ect_ret = 0;
>>> -    struct coresight_device *ect_csdev = csdev->ect_dev;
>>> -    struct module *mod;
>>> +    int i;
>>> +    struct coresight_connection conn = {};
>>> +    struct coresight_connection *new_conn;
>>>    -    if (!ect_csdev)
>>> -        return 0;
>>> -    if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
>>> -        return 0;
>>> +    mutex_lock(&coresight_mutex);
>>> +    conn.dest_fwnode = fwnode_handle_get(dev_fwnode(&helper->dev));
>>> +    conn.dest_dev = helper;
>>> +    conn.dest_port = conn.src_port = -1;
>>> +    conn.src_dev = csdev;
>>>    -    mod = ect_csdev->dev.parent->driver->owner;
>>> -    if (enable) {
>>> -        if (try_module_get(mod)) {
>>> -            ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
>>> -            if (ect_ret) {
>>> -                module_put(mod);
>>> -            } else {
>>> -                get_device(ect_csdev->dev.parent);
>>> -                csdev->ect_enabled = true;
>>> -            }
>>> -        } else
>>> -            ect_ret = -ENODEV;
>>> -    } else {
>>> -        if (csdev->ect_enabled) {
>>> -            ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
>>> -            put_device(ect_csdev->dev.parent);
>>> -            module_put(mod);
>>> -            csdev->ect_enabled = false;
>>> -        }
>>> -    }
>>> +    /*
>>> +     * Check for duplicates because this is called every time a helper
>>> +     * device is re-loaded. Existing connections will get re-linked
>>> +     * automatically.
>>> +     */
>>> +    for (i = 0; i < csdev->pdata->nr_outconns; ++i)
>>> +        if (csdev->pdata->out_conns[i]->dest_fwnode == conn.dest_fwnode)
>>> +            goto unlock;
>>>    -    /* output warning if ECT enable is preventing trace operation */
>>> -    if (ect_ret)
>>> -        dev_info(&csdev->dev, "Associated ECT device (%s) %s failed\n",
>>> -             dev_name(&ect_csdev->dev),
>>> -             enable ? "enable" : "disable");
>>> -    return ect_ret;
>>> -}
>>> +    new_conn =
>>> +        coresight_add_out_conn(csdev->dev.parent, csdev->pdata, &conn);
>>
>> ultra minor nit:
>>      new_conn = coresight_add_out_conn(....,
>>                        .... );
> 
> This whole patchset is now formatted with the kernel clang-format rules.
> Are you sure this one is against the conventions?

It is not against convention, but there are no hard line rules for
these.

The only suggestion is to split the lines sensibly with
readability stressed.

https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings

"Statements longer than 80 columns should be broken into sensible 
chunks, unless exceeding 80 columns significantly increases readability 
and does not hide information.

Descendants are always substantially shorter than the parent and are 
placed substantially to the right. A very commonly used style is to 
align descendants to a function open parenthesis."


I personally find it :

	result = rather_long_function_statement(arg1, arg2,
					        ........);

way better readable than :

	result =
		rather_long_function_statement(.....);

> 
> The problem is running the formatter on all changed lines makes it
> almost impossible to go back and undo indents like this.

Haven't used it, but it does seem to say it may not be perfect ;-).
That said, I am not too strict about this. You may leave it unchanged
if it is painful.

Suzuki



  reply	other threads:[~2023-04-24 13:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 15:51 [PATCH v5 00/13] " James Clark
2023-04-04 15:51 ` [PATCH v5 01/13] coresight: Fix loss of connection info when a module is unloaded James Clark
2023-04-12 13:12   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 02/13] coresight: Use enum type for cs_mode wherever possible James Clark
2023-04-04 15:51 ` [PATCH v5 03/13] coresight: Change name of pdata->conns James Clark
2023-04-04 15:51 ` [PATCH v5 04/13] coresight: Rename nr_outports to nr_outconns James Clark
2023-04-04 15:51 ` [PATCH v5 05/13] coresight: Rename connection members to make the direction explicit James Clark
2023-04-12 13:32   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 06/13] coresight: Dynamically add connections James Clark
2023-04-12 14:35   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 07/13] coresight: Store pointers to connections rather than an array of them James Clark
2023-04-12 14:49   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 08/13] coresight: Simplify connection fixup mechanism James Clark
2023-04-12 14:55   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 09/13] coresight: Store in-connections as well as out-connections James Clark
2023-04-12 15:17   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 10/13] coresight: Make refcount a property of the connection James Clark
2023-04-12 15:57   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 11/13] coresight: Refactor out buffer allocation function for ETR James Clark
2023-04-12 16:06   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 12/13] coresight: Enable and disable helper devices adjacent to the path James Clark
2023-04-17 12:00   ` Mike Leach
2023-04-04 15:51 ` [PATCH v5 13/13] coresight: Fix CTI module refcount leak by making it a helper device James Clark
2023-04-17 13:36   ` Mike Leach
2023-04-24 10:43   ` Suzuki K Poulose
2023-04-24 11:09     ` James Clark
2023-04-24 13:22       ` Suzuki K Poulose [this message]
2023-04-25 14:41         ` James Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7dab2287-97ce-7603-9b9e-445135758d09@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.clark@arm.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=quic_jinlmao@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®