All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leo Yu-Chi Liang" <leo.liang@sifive.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 10/10] gtrace: rvtrace: Add copyto_auxbuf callback for pre-ratified encoder and funnel
Date: Thu, 26 Nov 2026 09:32:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-235140@kernel.org> (raw)
In-Reply-To: <20261126-send-preratified-trace-v1-10-1e686fd75be7@sifive.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] gtrace: rvtrace: type confusion and NULL deref in
  rvtrace_ramsink_cleanup()
- [Medium] gtrace: rvtrace: missing rvtrace_comp_poll_empty() in
  rvtrace_encoder_stop()
--

commit 50f4d76e6d06a1e94d9b5cf4a9095834e649bfc1
Author: Eric Lin <eric.lin@sifive.com>

gtrace: rvtrace: Add copyto_auxbuf callback for pre-ratified encoder and funnel

This commit adds rvtrace_v0_ramsink_copyto_auxbuf() to copy trace data
from pre-ratified encoders and funnels acting as sinks into the perf AUX
buffer, and updates gtrace_path_copyto_auxbuf() to invoke copyto_auxbuf()
only on the path's sink component.

> diff --git a/drivers/hwtracing/gtrace/rvtrace-encoder.c b/drivers/hwtracing/gtrace/rvtrace-encoder.c
> index 8d2f7ac5e0fe4..a854c4695351c 100644
> --- a/drivers/hwtracing/gtrace/rvtrace-encoder.c
> +++ b/drivers/hwtracing/gtrace/rvtrace-encoder.c
> @@ -164,6 +164,15 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)
>  	return 0;
>  }
>  
> +static size_t rvtrace_encoder_copyto_auxbuf(struct gtrace_component *comp,
> +					    struct gtrace_perf_auxbuf *buf,
> +					    u64 *format)
> +{
> +	struct rvtrace_encoder_priv *priv = dev_get_drvdata(&comp->dev);
> +
> +	return rvtrace_v0_ramsink_copyto_auxbuf(comp, priv->sink, buf, format);
> +}

[Severity: Medium]
Can rvtrace_encoder_copyto_auxbuf() read the hardware write pointer and
copy the DMA buffer before pending trace writes have drained when a
pre-ratified encoder acts as a sink?

Unlike rvtrace_funnel_stop() and rvtrace_ramsink_stop(),
rvtrace_encoder_stop() does not call rvtrace_comp_poll_empty(comp) after
gtrace_disable_component(comp):

drivers/hwtracing/gtrace/rvtrace-encoder.c:rvtrace_encoder_stop() {
    ...
	err = gtrace_disable_component(comp);
	if (err)
		dev_err(&comp->dev, "failed to disable encoder.\n");

	return ret ?: err;
}

When gtrace_event_stop() calls gtrace_path_stop() followed immediately by
gtrace_path_copyto_auxbuf(), copying before
RVTRACE_COMPONENT_CTRL_EMPTY_SHIFT asserts can truncate the trace data in
the perf AUX buffer.

[ ... ]

> diff --git a/drivers/hwtracing/gtrace/rvtrace-ramsink.c b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
> index f183dcd71c7c0..cc0a5785bda40 100644
> --- a/drivers/hwtracing/gtrace/rvtrace-ramsink.c
> +++ b/drivers/hwtracing/gtrace/rvtrace-ramsink.c

[ ... ]

> @@ -448,6 +455,28 @@ void rvtrace_v0_ramsink_release(struct gtrace_component *comp,
>  	of_reserved_mem_device_release(comp->pdata->dev);
>  }
>  EXPORT_SYMBOL_GPL(rvtrace_v0_ramsink_release);
> +
> +/**
> + * rvtrace_v0_ramsink_copyto_auxbuf() - Copy trace data from the sink embedded
> + * in a pre-ratified trace encoder/funnel into the perf AUX buffer.
> + * @comp:   Pre-ratified trace encoder/funnel component.
> + * @priv:   Sink private data returned by rvtrace_v0_ramsink_setup().
> + * @buf:    Perf AUX buffer.
> + * @format: Trace format of the copied data.
> + *
> + * Return: Number of bytes copied, 0 if the component doesn't act as a sink.
> + */
> +size_t rvtrace_v0_ramsink_copyto_auxbuf(struct gtrace_component *comp,
> +					struct rvtrace_ramsink_priv *priv,
> +					struct gtrace_perf_auxbuf *buf,
> +					u64 *format)
> +{
> +	if (!priv)
> +		return 0;
> +
> +	return __rvtrace_ramsink_copyto_auxbuf(comp, priv, buf, format);
> +}
> +EXPORT_SYMBOL_GPL(rvtrace_v0_ramsink_copyto_auxbuf);

[Severity: High]
While rvtrace_v0_ramsink_copyto_auxbuf() passes priv explicitly to
__rvtrace_ramsink_copyto_auxbuf(), doesn't rvtrace_v0_ramsink_release()
right above still drop its priv argument and read dev_get_drvdata() via
rvtrace_ramsink_cleanup()?

drivers/hwtracing/gtrace/rvtrace-ramsink.c:rvtrace_ramsink_cleanup() {
	struct rvtrace_ramsink_priv *priv = dev_get_drvdata(&comp->dev);

	dma_free_coherent(comp->pdata->dev, priv->alloc_size, priv->alloc_va, priv->alloc_start);
}

For a pre-ratified encoder or funnel, comp->dev driver data holds struct
rvtrace_encoder_priv or struct rvtrace_funnel_priv rather than struct
rvtrace_ramsink_priv (and is still NULL if gtrace_enable_component()
fails in rvtrace_funnel_probe()).  Calling rvtrace_v0_ramsink_release()
on probe failure or driver unbind either dereferences NULL or reads past
the end of the encoder/funnel private struct and passes garbage to
dma_free_coherent(), while leaking the sink's coherent DMA buffer.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-send-preratified-trace-v1-0-1e686fd75be7@sifive.com?part=10

      reply	other threads:[~2026-11-26  9:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:07 [PATCH 00/10] gtrace: Add support for SiFive pre-ratified RISC-V trace components Leo Yu-Chi Liang
2026-11-26  9:07 ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 01/10] dt-bindings: riscv: Add SiFive pre-ratified " Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 02/10] gtrace: rvtrace: Add pre-ratified implementation callback Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 03/10] gtrace: rvtrace: Add pre-ratified private data callback Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 04/10] gtrace: rvtrace: Add pre-ratified encoder support Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 05/10] gtrace: Terminate id_table iteration on GTRACE_COMPONENT_TYPE_NONE Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 06/10] gtrace: rvtrace: Add pre-ratified trace sink config Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 07/10] gtrace: rvtrace: Add pre-ratified trace funnel driver Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:19   ` sashiko-bot
2026-11-26  9:07 ` [PATCH 08/10] gtrace: rvtrace: Introduce struct rvtrace_ramsink_regs to abstract register offsets Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 09/10] gtrace: rvtrace: Add pre-ratified ramsink setup Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:19   ` sashiko-bot
2026-11-26  9:07 ` [PATCH 10/10] gtrace: rvtrace: Add copyto_auxbuf callback for pre-ratified encoder and funnel Leo Yu-Chi Liang
2026-11-26  9:07   ` Leo Yu-Chi Liang
2026-11-26  9:32   ` sashiko-bot [this message]

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=sashiko-outbox-235140@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=leo.liang@sifive.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.