From: sashiko-bot@kernel.org
To: "Abhinav Parihar" <abhinav.parihar@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3] misc: fastrpc: Add cache maintenance for non-coherent platforms
Date: Tue, 24 Nov 2026 12:38:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-231159@kernel.org> (raw)
In-Reply-To: <20261124120604.2640046-1-abhinav.parihar@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] misc: fastrpc: skipped dma_buf cache maintenance due to mstart
and overlap
- [Medium] misc: fastrpc: unchecked dma_buf_begin_cpu_access() in cache
helpers
- [Medium] misc: fastrpc: redundant full-buffer cache passes in
fastrpc_inv_args()
- [Medium] misc: fastrpc: repeated full-dma_buf cache flushes for shared
dma_buf args
--
commit 38d28b3641886dcb390560c25b96a33e1bd0dc19
Author: Abhinav Parihar <abhinav.parihar@oss.qualcomm.com>
misc: fastrpc: Add cache maintenance for non-coherent platforms
This commit adds DMA-buf cache flush and invalidation helpers for RPC
argument buffers on platforms whose session device is not DMA-coherent.
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 9e760f68bcaf2..39ad0ab88aec3 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
[ ... ]
> @@ -666,7 +668,9 @@ static int olaps_cmp(const void *a, const void *b)
> static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx)
> {
> u64 max_end = 0;
> + int max_raix = -1;
> int i;
> + int inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
>
> for (i = 0; i < ctx->nbufs; ++i) {
> ctx->olaps[i].start = ctx->args[i].ptr;
> @@ -685,7 +689,10 @@ static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx)
>
> if (ctx->olaps[i].end > max_end) {
> max_end = ctx->olaps[i].end;
> + max_raix = ctx->olaps[i].raix;
> } else {
> + if ((max_raix < inbufs) != (ctx->olaps[i].raix < inbufs))
> + ctx->olaps[i].do_cmo = true;
> ctx->olaps[i].mend = 0;
> ctx->olaps[i].mstart = 0;
> }
> @@ -695,6 +702,7 @@ static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx)
> ctx->olaps[i].mstart = ctx->olaps[i].start;
> ctx->olaps[i].offset = 0;
> max_end = ctx->olaps[i].end;
> + max_raix = ctx->olaps[i].raix;
> }
> }
> }
[Severity: High]
Can fastrpc_get_buff_overlaps() leave both mstart and do_cmo as zero for
mapped DMA-buf arguments that still require cache maintenance in
fastrpc_flush_args() and fastrpc_inv_args()?
First, for a mapped DMA-buf argument passed with args[i].ptr == 0 and a
non-zero length (such as in fastrpc_init_create_process() when init.file is
0, or in fastrpc_get_args() where vma_lookup() is optional), the non-overlap
branch sets mstart = start = 0 and leaves do_cmo = false. Because
fastrpc_flush_args() and fastrpc_inv_args() check
(ctx->olaps[i].mstart || ctx->olaps[i].do_cmo) rather than a non-empty range,
cache maintenance is skipped whenever mstart is 0.
Second, overlaps are computed solely from user virtual addresses across all
arguments without checking whether overlapping entries share the same DMA-buf
FD or even have a map, and only a single max_raix is tracked. If an inline
buffer or a different DMA-buf of the same direction encloses a mapped DMA-buf
range, or if an input DMA-buf is partially overlapped by an output buffer
that advances max_end and overwrites max_raix before an enclosed output range
referencing the first DMA-buf is checked, mstart is zeroed and do_cmo remains
false, skipping the flush or invalidation and leaving stale data between the
CPU and DSP.
[ ... ]
> @@ -1078,6 +1086,54 @@ static int fastrpc_create_maps(struct fastrpc_invoke_ctx *ctx)
> return 0;
> }
>
> +static void fastrpc_flush_args(struct fastrpc_invoke_ctx *ctx)
> +{
> + union fastrpc_remote_arg *rpra = ctx->rpra;
> + int i, inbufs;
> +
> + inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
> +
> + for (i = 0; i < ctx->nbufs; ++i) {
> + int raix = ctx->olaps[i].raix;
> + struct fastrpc_map *map = ctx->maps[raix];
> +
> + if (raix + 1 > inbufs)
> + continue;
> + if (!map || !map->buf)
> + continue;
> +
> + if (rpra[raix].buf.len && (ctx->olaps[i].mstart || ctx->olaps[i].do_cmo)) {
> + dma_buf_begin_cpu_access(map->buf, DMA_TO_DEVICE);
> + dma_buf_end_cpu_access(map->buf, DMA_TO_DEVICE);
[Severity: Medium]
Should fastrpc_flush_args() and fastrpc_inv_args() check the return value of
dma_buf_begin_cpu_access() and propagate errors to their callers?
dma_buf_begin_cpu_access() can fail (for example with -ERESTARTSYS while
waiting interruptibly on reservation fences in __dma_buf_begin_cpu_access()),
and ignoring the failure unconditionally calls dma_buf_end_cpu_access() and
proceeds with the RPC on unsynchronized buffers.
> + }
> + }
> +}
[Severity: Medium]
Does iterating over ctx->nbufs without deduplicating by map->buf flush or
invalidate the entire parent dma_buf multiple times when several argument
slices share one DMA-buf FD?
dma_buf_begin_cpu_access() and dma_buf_end_cpu_access() synchronize the full
dma_buf scatterlist rather than the argument sub-range, so K non-enclosed (or
do_cmo) slices carved from the same dma_buf trigger K full-buffer cache walks
in fastrpc_flush_args() and fastrpc_inv_args().
> +
> +static void fastrpc_inv_args(struct fastrpc_invoke_ctx *ctx)
> +{
> + union fastrpc_remote_arg *rpra = ctx->rpra;
> + int i, inbufs;
> +
> + inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
> +
> + for (i = 0; i < ctx->nbufs; ++i) {
> + int raix = ctx->olaps[i].raix;
> + struct fastrpc_map *map = ctx->maps[raix];
> +
> + if (raix + 1 <= inbufs)
> + continue;
> + if (!rpra[raix].buf.len)
> + continue;
> + if (!map || !map->buf)
> + continue;
> +
> + if (ctx->olaps[i].mstart || ctx->olaps[i].do_cmo) {
> + dma_buf_begin_cpu_access(map->buf, DMA_FROM_DEVICE);
> + dma_buf_end_cpu_access(map->buf, DMA_FROM_DEVICE);
> + }
> + }
> +}
[ ... ]
> @@ -1387,6 +1446,8 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
> if (err)
> goto bail;
>
> + if (!fl->sctx->coherent)
> + fastrpc_inv_args(ctx);
> /* make sure that all CPU memory writes are seen by DSP */
> dma_wmb();
> /* Send invoke buffer to remote dsp */
> @@ -1407,6 +1468,9 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
>
> /* make sure that all memory writes by DSP are seen by CPU */
> dma_rmb();
> + if (!fl->sctx->coherent)
> + fastrpc_inv_args(ctx);
[Severity: Medium]
Why does fastrpc_inv_args() call both dma_buf_begin_cpu_access() and
dma_buf_end_cpu_access() both before and after the RPC invocation?
In standard DMA-buf exporters (such as system_heap and cma_heap),
begin_cpu_access(DMA_FROM_DEVICE) syncs the buffer for the CPU (cache
invalidate on arm64) and end_cpu_access(DMA_FROM_DEVICE) syncs it for the
device (cache clean on arm64). Calling fastrpc_inv_args() before
fastrpc_invoke_send() and again after fastrpc_wait_for_completion() performs
four full-buffer cache passes per output buffer instead of syncing for the
device before the RPC and syncing for the CPU after completion.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124120604.2640046-1-abhinav.parihar@oss.qualcomm.com?part=1
prev parent reply other threads:[~2026-11-24 12:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:06 [PATCH v3] misc: fastrpc: Add cache maintenance for non-coherent platforms Abhinav Parihar
2026-11-24 12:29 ` Arnd Bergmann
2026-11-24 12:38 ` 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-231159@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=abhinav.parihar@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox