mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Mark Brown" <broonie@kernel.org>
Cc: "Petr Tesarik" <ptesarik@suse.com>,
	"Grant Likely" <grant.likely@secretlab.ca>,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Subject: Re: [PATCH] spi: Ensure memory used for spi_write_then_read() is DMA safe
Date: Wed, 26 Mar 2025 22:45:57 +0100	[thread overview]
Message-ID: <92817727-d0f2-4d91-8fef-84ee92ab42e7@app.fastmail.com> (raw)
In-Reply-To: <8ff02f5a-fa66-4403-b193-a18c23879e0d@sirena.org.uk>

On Wed, Mar 26, 2025, at 17:20, Mark Brown wrote:
> On Fri, Mar 21, 2025 at 08:42:12PM +0100, Arnd Bergmann wrote:
>> Using dma_alloc_noncoherent() should make the implementation
>> much nicer than GFP_DMA in the past, so we could add a bus
>> specific helper for SPI that checks if the controller actually
>> wants to do DMA and whether the buffer is problematic at all,
>> and then decides to either allocate a bounce buffer and
>> fill the sg table with the correct DMA address, map the
>> existing buffer, or pass it without mapping depending on
>> what the device needs.
>
> That query feels a lot like spi_optimize_message().  Which should
> possibly then just do the bouncing if it's needed.

Would that require attaching the temporary buffer to the message
or could that be a permanent bounce buffer?

The idea I had come up with was to have one or two pages
permanently allocated in the spi_controller, the spi_device
or the regmap and then use appropriate serialization to
ensure only one transfer uses it at a time, similar to
how spi_controller->dummy_tx gets allocated, or how
spi_write_then_read() uses its small global buffer.

The advantage of using a permanent buffer is that it
avoids both the kmalloc and the iommu mapping in the fast
path and only needs to do the dma_sync_single_()
for cache management, which should be faster for small
transfers.

The downside would be a higher memory usage and the
need for a mutex.

      Arnd

  reply	other threads:[~2025-03-26 21:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-27  6:35 Mark Brown
2013-02-05 14:21 ` Grant Likely
2025-03-20 11:43   ` Petr Tesarik
2025-03-20 12:29     ` Mark Brown
2025-03-20 13:35       ` Arnd Bergmann
2025-03-20 14:35         ` Petr Tesarik
2025-03-20 15:34           ` Mark Brown
2025-03-20 16:08             ` Petr Tesarik
2025-03-20 18:55               ` Mark Brown
2025-03-20 14:42         ` Mark Brown
2025-03-20 16:30           ` Arnd Bergmann
2025-03-20 18:39             ` Mark Brown
2025-03-21 12:41               ` Arnd Bergmann
2025-03-21 14:13                 ` Petr Tesarik
2025-03-21 21:21                   ` Arnd Bergmann
2025-03-21 14:45                 ` Mark Brown
2025-03-21 19:42                   ` Arnd Bergmann
2025-03-26 16:20                     ` Mark Brown
2025-03-26 21:45                       ` Arnd Bergmann [this message]
2025-03-27 15:03                         ` Mark Brown

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=92817727-d0f2-4d91-8fef-84ee92ab42e7@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=ptesarik@suse.com \
    /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®