Re: [PATCH v3] misc: fastrpc: Add cache maintenance for non-coherent platforms
From: Arnd Bergmann
Date: Tue Nov 24 2026 - 07:29:48 EST
On Tue, Nov 24, 2026, at 13:06, Abhinav Parihar wrote:
> Some platforms using fastrpc do not support DMA coherency on
> HLOS. On such systems, explicit cache maintenance is
> required to ensure data consistency for RPC argument buffers.
>
> Add cache maintenance for argument buffers when operating on
> non-coherent platforms:
> - Flush input buffers before invoking RPC to ensure CPU writes are
> visible to the DSP
> - Invalidate output buffers after RPC completion to ensure DSP
> writes are visible to the CPU
>
> Introduce helper functions fastrpc_flush_args() and
> fastrpc_inv_args() to perform the required dma-buf cache
> operations. These are invoked only when the device is not marked
> as DMA coherent.
>
> The coherency capability is determined using the "dma-coherent"
> device tree property and stored per session context.
The dma-mapping abstraction is meant to hide this from drivers,
why does this driver need to know?
> @@ -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);
> + }
> + }
> +}
This does not look like an appropriate interface: the driver
should not have to worry about platform specific details
of 'flush' or 'invalidate' and only access the data between
'begin' and 'end' here. E.g. if there is an iommu or swiotlb,
the buffer may become inaccessible again after 'end'.
Can you change this to have separate loops to manage
ownership before and after the access?
Arnd