From: James Clark <james.clark@arm.com>
To: Linu Cherian <lcherian@marvell.com>,
suzuki.poulose@arm.com, mike.leach@linaro.org,
leo.yan@linaro.org
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>
Subject: Re: [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot
Date: Wed, 4 Oct 2023 14:48:04 +0100 [thread overview]
Message-ID: <9b519a19-548c-dec0-ed69-52695ff12a69@arm.com> (raw)
In-Reply-To: <acc2a406-2cff-eb3b-7661-1a93d4749bf2@arm.com>
On 03/10/2023 17:43, James Clark wrote:
>
>
> On 29/09/2023 14:37, Linu Cherian wrote:
>> * Introduce a new mode CS_MODE_READ_PREVBOOT for reading tracedata
>> captured in previous boot.
>>
>> * Add special handlers for preparing ETR/ETF for this special mode
>>
>> * User can read the trace data as below
>>
>> For example, for reading trace data from tmc_etf sink
>>
>> 1. cd /sys/bus/coresight/devices/tmc_etfXX/
>>
>> 2. Change mode to READ_PREVBOOT
>>
>> #echo 1 > read_prevboot
>>
>> 3. Dump trace buffer data to a file,
>>
>> #dd if=/dev/tmc_etrXX of=~/cstrace.bin
>>
>> 4. Reset back to normal mode
>>
>> #echo 0 > read_prevboot
>>
>> 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>
>> ---
>> .../coresight/coresight-etm4x-core.c | 1 +
>> .../hwtracing/coresight/coresight-tmc-core.c | 81 +++++++++-
>> .../hwtracing/coresight/coresight-tmc-etf.c | 62 ++++++++
>> .../hwtracing/coresight/coresight-tmc-etr.c | 145 +++++++++++++++++-
>> drivers/hwtracing/coresight/coresight-tmc.h | 6 +
>> include/linux/coresight.h | 13 ++
>> 6 files changed, 306 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> index 77b0271ce6eb..513baf681280 100644
>> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> @@ -1010,6 +1010,7 @@ static void etm4_disable(struct coresight_device *csdev,
>>
>> switch (mode) {
>> case CS_MODE_DISABLED:
>> + case CS_MODE_READ_PREVBOOT:
>> 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 6658ce76777b..65c15c9f821b 100644
>> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
>> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
>> @@ -103,6 +103,45 @@ u32 tmc_get_memwidth_mask(struct tmc_drvdata *drvdata)
>> return mask;
>> }
>>
>> +int tmc_read_prepare_prevboot(struct tmc_drvdata *drvdata)
>> +{
>> + int ret = 0;
>> + struct tmc_register_snapshot *reg_ptr;
>> + struct coresight_device *csdev = drvdata->csdev;
>> +
>> + if (!drvdata->metadata.vaddr) {
>> + ret = -ENOMEM;
>> + goto out;
>> + }
>> +
>> + reg_ptr = drvdata->metadata.vaddr;
>> + if (!reg_ptr->valid) {
>> + dev_err(&drvdata->csdev->dev,
>> + "Invalid metadata captured from previous boot\n");
>> + ret = -EINVAL;
>> + goto out;
>> + }
>
> I'm wondering if a more robust check is needed than the valid flag, like
> a checksum or something. I didn't debug it yet but I ended up with an
> invalid set of metadata after a panic reboot, see below. I'm not sure if
> it's just a logic bug or something got lost during the reboot, I didn't
> debug it yet. But I suppose unless you assume the panic didn't affect
> writing the metadata, then it could be partially written and shouldn't
> be trusted?
>
> [...]
>> +
>> +static int tmc_etr_sync_prevboot_buf(struct tmc_drvdata *drvdata)
>> +{
>> + u32 status;
>> + u64 rrp, rwp, dba;
>> + struct tmc_register_snapshot *reg_ptr;
>> + struct etr_buf *etr_buf = drvdata->prevboot_buf;
>> +
>> + reg_ptr = drvdata->metadata.vaddr;
>> +
>> + rrp = reg_ptr->rrp;
>> + rwp = reg_ptr->rwp;
>> + dba = reg_ptr->dba;
>> + status = reg_ptr->sts;
>> +
>> + etr_buf->full = !!(status & TMC_STS_FULL);
>> +
>> + /* Sync the buffer pointers */
>> + etr_buf->offset = rrp - dba;
>> + if (etr_buf->full)
>> + etr_buf->len = etr_buf->size;
>> + else
>> + etr_buf->len = rwp - rrp;
>> +
>> + /* Sanity checks for validating metadata */
>> + if ((etr_buf->offset > etr_buf->size) ||
>> + (etr_buf->len > etr_buf->size))
>> + return -EINVAL;
>
> The values I got here are 0x781b67182aa346f9 0x8000000 0x8000000 for
> offset, size and len respectively. This fails the first check. It would
> also be nice to have a dev_dbg here as well, it's basically the same as
> the valid check above which does have one.
>
So I debugged it and the issue is that after the panic I was doing a
cold boot rather than a warm boot and the memory was being randomised.
The reason that 0x8000000 seemed to be initialised is because they are
based on the reserved region size, rather than anything from the
metadata. When I examined the metadata it was all randomised.
That leads me to think that the single bit for 'valid' is insufficient.
There is a simple hashing function in include/linux/stringhash.h that we
could use on the whole metadata struct, but that specifically says:
* These hash functions are NOT GUARANTEED STABLE between kernel
* versions, architectures, or even repeated boots of the same kernel.
* (E.g. they may depend on boot-time hardware detection or be
* deliberately randomized.)
Although I'm not sure how true the repeated boots of the same kernel
part is.
Maybe something in include/crypto/hash.h could be used instead, or make
our own simple hash.
next prev parent reply other threads:[~2023-10-04 13:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-29 13:37 [PATCH 0/7] Coresight for Kernel panic and watchdog reset Linu Cherian
2023-09-29 13:37 ` [PATCH 1/7] dt-bindings: arm: coresight-tmc: Add "memory-region" property Linu Cherian
2023-09-30 15:28 ` Krzysztof Kozlowski
2023-10-03 4:33 ` [EXT] " Linu Cherian
2023-10-03 6:31 ` Krzysztof Kozlowski
2023-10-06 4:27 ` Linu Cherian
2023-10-06 11:03 ` Mike Leach
2023-10-14 11:36 ` [EXT] " Linu Cherian
2023-10-14 13:25 ` Conor Dooley
2023-10-19 1:12 ` Linu Cherian
2023-11-07 11:07 ` Linu Cherian
2023-09-29 13:37 ` [PATCH 2/7] coresight: tmc-etr: Add support to use reserved trace memory Linu Cherian
2023-10-02 14:28 ` James Clark
2023-10-02 14:41 ` James Clark
2023-10-02 15:03 ` James Clark
2023-10-03 4:34 ` [EXT] " Linu Cherian
2023-09-29 13:37 ` [PATCH 3/7] coresight: core: Add provision for panic callbacks Linu Cherian
2023-09-29 13:37 ` [PATCH 4/7] coresight: tmc: Enable panic sync handling Linu Cherian
2023-09-29 13:37 ` [PATCH 5/7] coresight: tmc: Add support for reading tracedata from previous boot Linu Cherian
2023-10-03 16:43 ` James Clark
2023-10-04 13:48 ` James Clark [this message]
2023-10-10 13:23 ` [EXT] " Linu Cherian
2023-11-09 1:08 ` Linu Cherian
2023-11-09 10:15 ` James Clark
2023-09-29 13:37 ` [PATCH 6/7] coresight: tmc: Stop trace capture on FlIn Linu Cherian
2023-09-29 13:37 ` [PATCH 7/7] coresight: config: Add preloaded configuration 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=9b519a19-548c-dec0-ed69-52695ff12a69@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=leo.yan@linaro.org \
--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).