From: "Arnd Bergmann" <arnd@arndb.de>
To: "A. Sverdlin" <alexander.sverdlin@siemens.com>,
linux-kernel@vger.kernel.org
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Michael Walle" <mwalle@kernel.org>,
"Hui Wang" <hui.wang@canonical.com>,
"Mark Brown" <broonie@kernel.org>
Subject: Re: [PATCH] eeprom: at25: convert to spi-mem API
Date: Fri, 04 Jul 2025 12:09:38 +0200 [thread overview]
Message-ID: <d5be177d-505d-4d72-9d18-913e69c23ea8@app.fastmail.com> (raw)
In-Reply-To: <20250702222823.864803-1-alexander.sverdlin@siemens.com>
On Thu, Jul 3, 2025, at 00:28, A. Sverdlin wrote:
> static int at25_ee_read(void *priv, unsigned int offset,
> void *val, size_t count)
> {
> + u8 *bounce __free(kfree) = kmalloc(min(count, io_limit), GFP_KERNEL);
> struct at25_data *at25 = priv;
> char *buf = val;
I see nothing wrong with your patch, but the added bounce buffer
reminds me or a general problem with such buffers in the SPI
layer (and a couple of other places like it).
The problem is that kmalloc() does not take into account the
DMA mask of the device, which can have two suboptimal outcomes:
- on builds without SWIOTLB/IOMMU and an SPI host that has a DMA
mask smaller than RAM, dma_map_sg() fails down the line,
so either the transfer will fail or fall back to MMIO mode
- when SWIOTLB is available, dma_map_sg() will succeed but
require another copy into a second bounce buffer.
There are various drivers that work around the problem by using
GFP_DMA instead of GFP_KERNEL. This should be reliable on all
platforms, but means that the allocation comes from a potentially
really small pool and is more likely to fail. Ideally I think we
should not do that any more at all but find another way to
allocate bounce buffers for SPI transfers. The two ideas I had
were:
a) and a generic interface to ask for a buffer that can be used
by an SPI bus driver for efficient transfers, with the SPI
core code making an informed decision on using either kmalloc()
or dma_alloc_noncoherent() based on the size of the transfer
and the DMA mask.
b) push down the bouncing into the SPI core, so you can just
pass buffers from anywhere (stack, vmalloc, ...) and
ask for the lower parts of the stack to copy these into
an appropriate buffer if necessary. For the spi mem API
I suppose that would require assigning a flag in
spi_mem_op->data.
Arnd
next prev parent reply other threads:[~2025-07-04 10:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 22:28 A. Sverdlin
2025-07-04 10:09 ` Arnd Bergmann [this message]
2025-11-03 16:33 ` Christophe Leroy
2025-11-03 19:12 ` Sverdlin, Alexander
2025-11-03 21:46 ` Christophe Leroy
2025-11-03 22:29 ` Sverdlin, Alexander
2025-11-03 22:36 ` Christophe Leroy
2025-11-04 13:13 ` Sverdlin, Alexander
2025-11-04 13:24 ` Christophe Leroy
2025-11-04 23:15 ` Greg Kroah-Hartman
2025-11-05 7:20 ` Sverdlin, Alexander
2025-11-07 11:49 ` Sverdlin, Alexander
2025-11-07 13:08 ` Arnd Bergmann
2025-11-07 13:44 ` Sverdlin, Alexander
2025-11-08 10:05 ` Christophe Leroy
2025-11-08 11:14 ` Christophe Leroy
2025-11-08 11:41 ` Sverdlin, Alexander
2025-11-08 16:24 ` Christophe Leroy
2025-11-10 15:09 ` Sverdlin, Alexander
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=d5be177d-505d-4d72-9d18-913e69c23ea8@app.fastmail.com \
--to=arnd@arndb.de \
--cc=alexander.sverdlin@siemens.com \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hui.wang@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mwalle@kernel.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®