From: James Clark <james.clark@arm.com>
To: Linu Cherian <lcherian@marvell.com>
Cc: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org,
linux-kernel@vger.kernel.org, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
devicetree@vger.kernel.org, sgoutham@marvell.com,
gcherian@marvell.com, Anil Kumar Reddy <areddy3@marvell.com>,
Tanmay Jagdale <tanmay@marvell.com>,
suzuki.poulose@arm.com, mike.leach@linaro.org
Subject: Re: [PATCH v9 5/7] coresight: tmc: Add support for reading crash data
Date: Fri, 7 Jun 2024 15:17:31 +0100 [thread overview]
Message-ID: <9fe19909-ddfa-4595-99a5-e8edc0805ca8@arm.com> (raw)
In-Reply-To: <a676105a-2f38-498b-87cb-94e0c2406408@arm.com>
On 05/06/2024 17:09, James Clark wrote:
>
>
> On 05/06/2024 09:17, Linu Cherian wrote:
>> * Introduce a new mode CS_MODE_READ_CRASHDATA for reading trace
>> captured in previous crash/watchdog reset.
>>
>> * Add special device files for reading ETR/ETF crash data.
>>
>> * User can read the crash data as below
>>
>> For example, for reading crash data from tmc_etf sink
>>
>> #dd if=/dev/crash_tmc_etfXX of=~/cstrace.bin
>>
>> Signed-off-by: Anil Kumar Reddy <areddy3@marvell.com>
>> Signed-off-by: Tanmay Jagdale <tanmay@marvell.com>
>> Signed-off-by: Linu Cherian <lcherian@marvell.com>
>> ---
>> Changelog from v8:
>> * Added missing exit path in __tmc_probe
>> * Few whitespace fixes and a checkpatch fix.
>>
>> .../coresight/coresight-etm4x-core.c | 1 +
>> .../hwtracing/coresight/coresight-tmc-core.c | 150 ++++++++++++++++-
>> .../hwtracing/coresight/coresight-tmc-etf.c | 72 +++++++++
>> .../hwtracing/coresight/coresight-tmc-etr.c | 151 +++++++++++++++++-
>> drivers/hwtracing/coresight/coresight-tmc.h | 11 +-
>> include/linux/coresight.h | 13 ++
>> 6 files changed, 390 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> index a0bdfabddbc6..7924883476c6 100644
>> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> @@ -1011,6 +1011,7 @@ static void etm4_disable(struct coresight_device *csdev,
>>
>> switch (mode) {
>> case CS_MODE_DISABLED:
>> + case CS_MODE_READ_CRASHDATA:
>> break;
>> case CS_MODE_SYSFS:
>> etm4_disable_sysfs(csdev);
>> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
>> index daad08bc693d..0c145477ba66 100644
>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
>> @@ -106,6 +106,60 @@ u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata)
>> return mask;
>> }
>>
>> +int tmc_read_prepare_crashdata(struct tmc_drvdata *drvdata)
>> +{
>> + int ret = 0;
>> + struct tmc_crash_metadata *mdata;
>> + struct coresight_device *csdev = drvdata->csdev;
>> +
>> + if (!drvdata->crash_mdata.vaddr) {
>> + ret = -ENOMEM;
>> + goto out;
>> + }
>> +
>> + mdata = drvdata->crash_mdata.vaddr;
>> + /* Check data integrity of metadata */
>> + if (mdata->crc32_mdata != find_crash_metadata_crc(mdata)) {
>> + dev_dbg(&drvdata->csdev->dev,
>> + "CRC mismatch in tmc crash metadata\n");
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> + /* Check data integrity of tracedata */
>> + if (mdata->crc32_tdata != find_crash_tracedata_crc(drvdata, mdata)) {
>> + dev_dbg(&drvdata->csdev->dev,
>> + "CRC mismatch in tmc crash tracedata\n");
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> + /* Check for valid metadata */
>> + if (!mdata->valid) {
>> + dev_dbg(&drvdata->csdev->dev,
>> + "Data invalid in tmc crash metadata\n");
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>> + /* Sink specific crashdata mode preparation */
>> + ret = crashdata_ops(csdev)->prepare(csdev);
>> + if (ret)
>> + goto out;
>> +
>> + if (mdata->sts & 0x1)
>> + coresight_insert_barrier_packet(drvdata->buf);
>> +
>> +out:
>> + return ret;
>> +}
>> +
>> +int tmc_read_unprepare_crashdata(struct tmc_drvdata *drvdata)
>> +{
>> + struct coresight_device *csdev = drvdata->csdev;
>> +
>> + /* Sink specific crashdata mode preparation */
>> + return crashdata_ops(csdev)->unprepare(csdev);
>> +}
>> +
>> static int tmc_read_prepare(struct tmc_drvdata *drvdata)
>> {
>> int ret = 0;
>> @@ -156,6 +210,9 @@ static int tmc_open(struct inode *inode, struct file *file)
>> struct tmc_drvdata *drvdata = container_of(file->private_data,
>> struct tmc_drvdata, miscdev);
>>
>> + if (coresight_get_mode(drvdata->csdev) == CS_MODE_READ_CRASHDATA)
>> + return -EBUSY;
>> +
>> ret = tmc_read_prepare(drvdata);
>> if (ret)
>> return ret;
>> @@ -180,13 +237,12 @@ static inline ssize_t tmc_get_sysfs_trace(struct tmc_drvdata *drvdata,
>> return -EINVAL;
>> }
>>
>> -static ssize_t tmc_read(struct file *file, char __user *data, size_t len,
>> - loff_t *ppos)
>> +static ssize_t tmc_read_common(struct tmc_drvdata *drvdata, char __user *data,
>> + size_t len, loff_t *ppos)
>> {
>> char *bufp;
>> ssize_t actual;
>> - struct tmc_drvdata *drvdata = container_of(file->private_data,
>> - struct tmc_drvdata, miscdev);
>> +
>> actual = tmc_get_sysfs_trace(drvdata, *ppos, len, &bufp);
>> if (actual <= 0)
>> return 0;
>> @@ -203,6 +259,15 @@ static ssize_t tmc_read(struct file *file, char __user *data, size_t len,
>> return actual;
>> }
>>
>> +static ssize_t tmc_read(struct file *file, char __user *data, size_t len,
>> + loff_t *ppos)
>> +{
>> + struct tmc_drvdata *drvdata = container_of(file->private_data,
>> + struct tmc_drvdata, miscdev);
>> +
>> + return tmc_read_common(drvdata, data, len, ppos);
>> +}
>> +
>> static int tmc_release(struct inode *inode, struct file *file)
>> {
>> int ret;
>> @@ -225,6 +290,61 @@ static const struct file_operations tmc_fops = {
>> .llseek = no_llseek,
>> };
>>
>> +static int tmc_crashdata_open(struct inode *inode, struct file *file)
>> +{
>> + int ret;
>> + struct tmc_drvdata *drvdata = container_of(file->private_data,
>> + struct tmc_drvdata,
>> + crashdev);
>> +
>> + if (!coresight_take_mode(drvdata->csdev, CS_MODE_READ_CRASHDATA))
>> + return -EBUSY;
>> +
>> + ret = tmc_read_prepare(drvdata);
>> + if (ret) {
>> + coresight_set_mode(drvdata->csdev, CS_MODE_DISABLED);
>> + return ret;
>> + }
>> +
>> + nonseekable_open(inode, file);
>> +
>> + dev_dbg(&drvdata->csdev->dev, "%s: successfully opened\n", __func__);
>> + return 0;
>> +}
>> +
>> +static ssize_t tmc_crashdata_read(struct file *file, char __user *data,
>> + size_t len, loff_t *ppos)
>> +{
>> + struct tmc_drvdata *drvdata = container_of(file->private_data,
>> + struct tmc_drvdata,
>> + crashdev);
>> +
>> + return tmc_read_common(drvdata, data, len, ppos);
>> +}
>> +
>> +static int tmc_crashdata_release(struct inode *inode, struct file *file)
>> +{
>> + int ret = 0;
>> + struct tmc_drvdata *drvdata = container_of(file->private_data,
>> + struct tmc_drvdata,
>> + crashdev);
>> +
>> + ret = tmc_read_unprepare(drvdata);
>> +
>> + coresight_set_mode(drvdata->csdev, CS_MODE_DISABLED);
>> +
>> + dev_dbg(&drvdata->csdev->dev, "%s: released\n", __func__);
>> + return ret;
>> +}
>> +
>> +static const struct file_operations tmc_crashdata_fops = {
>> + .owner = THIS_MODULE,
>> + .open = tmc_crashdata_open,
>> + .read = tmc_crashdata_read,
>> + .release = tmc_crashdata_release,
>> + .llseek = no_llseek,
>> +};
>> +
>> static enum tmc_mem_intf_width tmc_get_memwidth(u32 devid)
>> {
>> enum tmc_mem_intf_width memwidth;
>> @@ -542,6 +662,18 @@ static u32 tmc_etr_get_max_burst_size(struct device *dev)
>> return burst_size;
>> }
>>
>> +static void register_crash_dev_interface(struct tmc_drvdata *drvdata,
>> + const char *name)
>> +{
>> + drvdata->crashdev.name =
>> + devm_kasprintf(&drvdata->csdev->dev, GFP_KERNEL, "%s_%s", "crash", name);
>> + drvdata->crashdev.minor = MISC_DYNAMIC_MINOR;
>> + drvdata->crashdev.fops = &tmc_crashdata_fops;
>> + if (misc_register(&drvdata->crashdev))
>> + dev_dbg(&drvdata->csdev->dev,
>> + "Failed to setup user interface for crashdata\n");
>> +}
>> +
>> static int __tmc_probe(struct device *dev, struct resource *res)
>> {
>> int ret = 0;
>> @@ -642,8 +774,13 @@ static int __tmc_probe(struct device *dev, struct resource *res)
>> drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
>> drvdata->miscdev.fops = &tmc_fops;
>> ret = misc_register(&drvdata->miscdev);
>> - if (ret)
>> + if (ret) {
>> coresight_unregister(drvdata->csdev);
>> + goto out;
>> + }
>> +
>> + if (is_tmc_reserved_region_valid(dev))
>> + register_crash_dev_interface(drvdata, desc.name);
>
> I think this would be better if it checked the CRC of the metadata in
> the same way it does before reading the file.
>
> Now we have two forms of "region valid", one that's any non-zero value,
> and the other "really valid" one. And because we don't check the CRC
> here we register a device that can't be used.
>
> I found it a bit confusing because without enabling debug prints I
> didn't know why the file couldn't be read. So I wasn't sure if it was
> because it wasn't valid or some other reason.
>
> I also wasn't able to get a valid region after booting the crash kernel.
> But maybe the memory isn't preserved across the reboot on my Juno, so I
> don't think that's necessarily an issue?
Ok so I double checked by writing 0x123456 into the reserved region and
confirmed that it _is_ preserved when booting the panic kernel on my
Juno. So I'm not sure why I wasn't able to read out the crash dump.
I did see the "success" message from tmc_panic_sync_etr() at least some
of the times, although I do remember it not printing out every time. I
don't know if this is just an issue with outputting to serial after a
panic or something else was going on?
Did you ever see the success message not print out? Or not able to read
back the data when you were testing it?
next prev parent reply other threads:[~2024-06-07 14:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-05 8:17 [PATCH v9 0/7] Coresight for Kernel panic and watchdog reset Linu Cherian
2024-06-05 8:17 ` [PATCH v9 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property Linu Cherian
2024-06-05 8:17 ` [PATCH v9 2/7] coresight: tmc-etr: Add support to use reserved trace memory Linu Cherian
2024-06-07 15:58 ` Suzuki K Poulose
2024-06-10 6:18 ` [EXTERNAL] " Linu Cherian
2024-06-05 8:17 ` [PATCH v9 3/7] coresight: core: Add provision for panic callbacks Linu Cherian
2024-06-05 16:09 ` James Clark
2024-06-20 4:12 ` Linu Cherian
2024-06-05 8:17 ` [PATCH v9 4/7] coresight: tmc: Enable panic sync handling Linu Cherian
2024-06-10 13:02 ` Suzuki K Poulose
2024-06-20 4:10 ` Linu Cherian
2024-06-20 8:25 ` James Clark
2024-06-05 8:17 ` [PATCH v9 5/7] coresight: tmc: Add support for reading crash data Linu Cherian
2024-06-05 10:30 ` James Clark
2024-06-20 4:14 ` Linu Cherian
2024-06-05 16:09 ` James Clark
2024-06-07 14:17 ` James Clark [this message]
2024-06-10 6:15 ` [EXTERNAL] " Linu Cherian
2024-06-10 13:15 ` James Clark
2024-06-10 16:34 ` Suzuki K Poulose
2024-06-20 1:48 ` Linu Cherian
2024-06-21 10:54 ` Suzuki K Poulose
2024-07-03 4:29 ` Linu Cherian
2024-07-03 9:39 ` Suzuki K Poulose
2024-07-11 5:49 ` Linu Cherian
2024-06-05 8:17 ` [PATCH v9 6/7] coresight: tmc: Stop trace capture on FlIn Linu Cherian
2024-06-05 8:17 ` [PATCH v9 7/7] coresight: config: Add preloaded configuration Linu Cherian
2024-06-10 13:06 ` [PATCH v9 0/7] Coresight for Kernel panic and watchdog reset Suzuki K Poulose
2024-06-10 13:22 ` James Clark
2024-06-20 1:50 ` Linu Cherian
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=9fe19909-ddfa-4595-99a5-e8edc0805ca8@arm.com \
--to=james.clark@arm.com \
--cc=areddy3@marvell.com \
--cc=conor+dt@kernel.org \
--cc=coresight@lists.linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=gcherian@marvell.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lcherian@marvell.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.leach@linaro.org \
--cc=robh+dt@kernel.org \
--cc=sgoutham@marvell.com \
--cc=suzuki.poulose@arm.com \
--cc=tanmay@marvell.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;
as well as URLs for NNTP newsgroup(s).