mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Abhinav Parihar" <abhinav.parihar@oss.qualcomm.com>,
	"Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
	linux-arm-msm@vger.kernel.org
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	quic_bkumar@quicinc.com,
	"Ekansh Gupta" <ekansh.gupta@oss.qualcomm.com>,
	linux-kernel@vger.kernel.org, quic_chennak@quicinc.com,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3] misc: fastrpc: Add cache maintenance for non-coherent platforms
Date: Mon, 30 Nov 2026 10:38:20 +0100	[thread overview]
Message-ID: <87f09bc1-d064-49c5-8821-a7e01efa01d9@app.fastmail.com> (raw)
In-Reply-To: <2c58c159-3062-4afd-8b28-0c7afc996345@oss.qualcomm.com>

On Mon, Nov 30, 2026, at 10:11, Abhinav Parihar wrote:
> On 11/24/2026 5:59 PM, Arnd Bergmann wrote:
>> On Tue, Nov 24, 2026, at 13:06, Abhinav Parihar wrote:
>>> 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.
>
> 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?

>>> +		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?
>
>
> 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.

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.

> 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

      reply	other threads:[~2026-11-30  9:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 12:06 Abhinav Parihar
2026-11-24 12:29 ` Arnd Bergmann
2026-11-30  9:11   ` Abhinav Parihar
2026-11-30  9:38     ` Arnd Bergmann [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=87f09bc1-d064-49c5-8821-a7e01efa01d9@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=abhinav.parihar@oss.qualcomm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ekansh.gupta@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_bkumar@quicinc.com \
    --cc=quic_chennak@quicinc.com \
    --cc=srinivas.kandagatla@linaro.org \
    /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

all inboxes | Powered by JetHome®