misc: fastrpc: Add cache maintenance for non-coherent platforms
PATCH v3 1/1 misc: fastrpc: Add cache maintenance for non-coherent platforms
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.
This ensures correct data synchronization on platforms lacking DMA coherency, while avoiding unnecessary overhead on coherent systems.
---
Patch [v2]: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Fix missing max_raix update causes incorrect do_cmo evaluation.
- Use of_dma_is_coherent() to determine device coherency.
- Simplify input/output buffer classification and overlap checks for cache maintenance.
Changes in v2:
- Fix buffer overlap handling to ensure cache maintenance is performed when input and output buffers overlap and the overlap calculation suppresses the buffer's mstart/mend range.
- Add a do_cmo flag to track buffers that require cache maintenance even when their overlap range is clipped.
- Invalidate output buffers before sending the RPC request, preventing stale CPU cache lines from being written back while the DSP updates the buffers.
- Use DMA_FROM_DEVICE consistently for both begin_cpu_access() and end_cpu_access() when invalidating output buffers.
drivers/misc/fastrpc.c | 67 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-)
drivers/misc/fastrpc.c +66 -1
@@ -222,6 +222,7 @@ struct fastrpc_buf_overlap {u64 mstart;u64 mend;u64 offset; +bool do_cmo; };struct fastrpc_buf {
@@ -297,6 +298,7 @@ struct fastrpc_session_ctx {int sid;bool used;bool valid; +bool coherent; };struct fastrpc_soc_data {
@@ -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; } } }
@@ -714,6 +722,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc(INIT_LIST_HEAD (&ctx->node); ctx->fl = user; + ctx->sc = sc; ctx->nscalars =REMOTE_SCALARS_LENGTH (sc); ctx->nbufs =REMOTE_SCALARS_INBUFS (sc) +REMOTE_SCALARS_OUTBUFS (sc);
@@ -739,7 +748,6 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc(/* Take a reference to user, released in fastrpc_context_free() */ fastrpc_user_get (user); - ctx->sc = sc; ctx->retval =-1 ; ctx->pid = current->pid; ctx->client_id = user->client_id;
@@ -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 ); + } + } +} + +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 ); + } + } +} +static struct fastrpc_invoke_buf *fastrpc_invoke_buf_start (union fastrpc_remote_arg *pra,int len) {return (struct fastrpc_invoke_buf *)(&pra[len]);
@@ -1202,6 +1258,9 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) } } +if (!ctx->fl->sctx->coherent) +fastrpc_flush_args (ctx); +for (i = ctx->nbufs; i < ctx->nscalars; ++i) { list[i].num = ctx->args[i].length ?1 :0 ; list[i].pgidx = i;
@@ -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); +/* populate all the output buffers with results */ err =fastrpc_put_args (ctx, kernel);if (err)
@@ -2370,6 +2434,7 @@ static int fastrpc_cb_init(struct platform_device *pdev) sess->used = false; sess->valid = true; sess->dev = dev; + sess->coherent =of_dma_is_coherent (dev->of_node); sess->sid = sid;if (cctx->domain_id ==CDSP_DOMAIN_ID )
Signature · 1 line
2.34.1
Arnd Bergmann
maintainerQuoted 11 lines · Abhinav Parihar
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
Quoted 7 lines
Introduce helper functions
fastrpc_flush_args()andfastrpc_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?
Quoted 18 lines
drivers/misc/fastrpc.c +13
-0@@ -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 ;
drivers/misc/fastrpc.c static int fastrpc_create_maps(struct · line 1112
Quoted 10 lines
drivers/misc/fastrpc.c +9
-0+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
Quoted 17 lines · Arnd Bergmann
Quoted 16 lines · Abhinav Parihar
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 CPUIntroduce helper functions
fastrpc_flush_args()andfastrpc_inv_args()to perform the required dma-buf cache operations. These are invoked only when the device is not marked as DMA coherent.
Quoted 4 lines
Quoted 2 lines
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?
I added that check because I thought coherency varied across targets and wanted to avoid unnecessary operations for IO coherent targets.
The data flow is that userspace allocates the dma-buf (system heap), FastRPC driver attaches and maps it for the HLOS SMMU, and the resulting IOVA is passed to the DSP, which maps and accesses the buffer in its own address space. Goal is that inbufs are updated in DDR before DSP reads them and outbufs cache lines are invalidated before HLOS reads the DSP results.
Quoted 34 lines
Quoted 18 lines
drivers/misc/fastrpc.c +13
-0@@ -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 ;drivers/misc/fastrpc.c static int fastrpc_create_maps(struct · line 1112
Quoted 10 lines
drivers/misc/fastrpc.c +9
-0+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'.
Quoted 4 lines
Can you change this to have separate loops to manage ownership before and after the access?
Arnd
I was calling dma_buf_begin_cpu_access() and dma_buf_end_cpu_access() back-to-back to trigger cache maintenance.
Currently we are treating these calls as flush/invalidate primitives.
Since FastRPC passes the mapping to the DSP rather than accessing the buffer contents in the kernel, could you advise which interface is appropriate for this case?
Arnd Bergmann
maintainerQuoted 12 lines · Abhinav Parihar
Quoted 6 lines · Arnd Bergmann
Quoted 3 lines · Abhinav Parihar
Some platforms using fastrpc do not support DMA coherency on 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?
I added that check because I thought coherency varied across targets and wanted to avoid unnecessary operations
for IO coherent targets.
Quoted 6 lines
The data flow is that userspace allocates the dma-buf (system heap), FastRPC driver attaches and maps it for the HLOS SMMU,
and the resulting IOVA is passed to the DSP, which maps and accesses the buffer in its own address space. Goal is that inbufs
are updated in DDR before DSP reads them and outbufs cache lines are invalidated before HLOS reads the DSP results.
I don't know what HLOS is, but the dma-mapping interface generally does handle this through the ownership model if you use it correctly.
I would generally recommend to have one of the devices that share the buffer allocate it instead of using the system heap that makes things a bit more complicated here.
Aside from FastRPC, what are the other devices that you expect to access the dma-buf? Is FastRPC the only one that may not be coherent, or are there others as well?
Quoted 13 lines
Quoted 13 lines
drivers/misc/fastrpc.c static int fastrpc_create_maps(struct fastrpc_invoke_ctx *ctx) · line 1110
Quoted 7 lines
(quoted diff) +1
-0+ if (rpra[raix].buf.len && (ctx->olaps[i].mstart ||ctx->olaps[i].do_cmo)) {
drivers/misc/fastrpc.c +5
-0+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'.
Quoted 8 lines
Quoted 2 lines
Can you change this to have separate loops to manage ownership before and after the access?
I was calling
dma_buf_begin_cpu_access()anddma_buf_end_cpu_access()back-to-back to trigger cache maintenance.Currently we are treating these calls as flush/invalidate primitives.
Right, my point was that this is not a portable way to do this because you rely on implementation details of the interface in order to do the exact thing that the interface was designed to do for you.
Quoted 3 lines
Since FastRPC passes the mapping to the DSP rather than accessing the buffer contents in the kernel, could you advise which interface is appropriate for this case?
Documentation/core-api/dma-api.rst explains the concept of the ownership model, the idea being that a buffer is at any point owned by either the device or the CPU, and you use dma_sync_single_for_{cpu,device}() to switch between the kernel. dmabuf extends this to allow multiple devices using dma_buf_begin_cpu_access() and dma_buf_end_cpu_access(), but the concept remains the same.
You can generally choose between having the mapping normally be on the device side and enclosing the CPU access in
a dma_buf_begin_cpu_access()/dma_buf_end_cpu_access() pair, or conceptually tying it to the CPU and enclosing the device access in the reverse dma_buf_end_cpu_access()/dma_buf_begin_cpu_access() pair. Since you seem to be dealing with multiple devices, you probably want the latter so the buffer is only ever owned
by one of the devices.
If the buffer is also mapped into userspace, you have the added complication of preventing userspace access while the buffer is owned by a device. You have the choice between risking data corruption for misbehaving userspace (which can be acceptable for certain types of data but not others), removing the user mapping during device access, or using a coherent mapping which requires expensive uncached user access if the device itself is not cache-coherent but avoids the explicit ownership management.
Arnd
[email protected]
AI reviewThank 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…
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 <[email protected]>
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.
Quoted 4 lines
drivers/misc/fastrpc.c +0
-0
[ ... ]
Quoted 22 lines
drivers/misc/fastrpc.c +5
-0@@ -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 ; }
drivers/misc/fastrpc.c static void fastrpc_get_buff_overlaps(struct fastrpc_invoke_ctx *ctx) · line 708
Quoted 7 lines
drivers/misc/fastrpc.c +1
-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.
[ ... ]
Quoted 13 lines
drivers/misc/fastrpc.c +9
-0@@ -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;
drivers/misc/fastrpc.c static int fastrpc_create_maps(struct fastrpc_invoke_ctx *ctx) · line 1107
Quoted 10 lines
drivers/misc/fastrpc.c +10
-0+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.
drivers/misc/fastrpc.c static int fastrpc_create_maps(struct fastrpc_invoke_ctx *ctx) · line 1110
Quoted 3 lines
drivers/misc/fastrpc.c +3
-0+ } + } +}
[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().
Quoted 25 lines
drivers/misc/fastrpc.c +25
-0+ +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 ); + } + } +}
[ ... ]
Quoted 10 lines
drivers/misc/fastrpc.c +2
-0@@ -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 */
drivers/misc/fastrpc.c static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, · line 1472
Quoted 5 lines
drivers/misc/fastrpc.c +2
-0@@ -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.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1