From: Robin Murphy <robin.murphy@arm.com>
To: Petr Tesarik <ptesarik@suse.com>,
Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Bagas Sanjaya <bagasdotme@gmail.com>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
Leon Romanovsky <leon@kernel.org>,
Keith Busch <kbusch@kernel.org>,
Caleb Sander Mateos <csander@purestorage.com>,
Sagi Grimberg <sagi@grimberg.me>, Jens Axboe <axboe@kernel.dk>,
John Garry <john.g.garry@oracle.com>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
iommu@lists.linux.dev
Subject: Re: [PATCH 7/8] docs: dma-api: update streaming DMA API physical address constraints
Date: Thu, 26 Jun 2025 10:58:00 +0100 [thread overview]
Message-ID: <bdb3a37a-a9d3-44c1-8eb7-41912c976ad1@arm.com> (raw)
In-Reply-To: <20250626070602.3d42b607@mordecai.tesarici.cz>
On 2025-06-26 6:06 am, Petr Tesarik wrote:
> On Thu, 26 Jun 2025 08:49:17 +0700
> Bagas Sanjaya <bagasdotme@gmail.com> wrote:
>
>> On Tue, Jun 24, 2025 at 03:39:22PM +0200, Petr Tesarik wrote:
>>> diff --git a/Documentation/core-api/dma-api.rst b/Documentation/core-api/dma-api.rst
>>> index cd432996949c..65132ec88104 100644
>>> --- a/Documentation/core-api/dma-api.rst
>>> +++ b/Documentation/core-api/dma-api.rst
>>> @@ -210,18 +210,12 @@ DMA_BIDIRECTIONAL direction isn't known
>>> this API should be obtained from sources which guarantee it to be
>>> physically contiguous (like kmalloc).
>>>
>>> - Further, the DMA address of the memory must be within the dma_mask of
>>> - the device. To ensure that the memory allocated by kmalloc is within
>>> - the dma_mask, the driver may specify various platform-dependent flags
>>> - to restrict the DMA address range of the allocation (e.g., on x86,
>>> - GFP_DMA guarantees to be within the first 16MB of available DMA
>>> - addresses, as required by ISA devices).
>>> -
>>> - Note also that the above constraints on physical contiguity and
>>> - dma_mask may not apply if the platform has an IOMMU (a device which
>>> - maps an I/O DMA address to a physical memory address). However, to be
>>> - portable, device driver writers may *not* assume that such an IOMMU
>>> - exists.
>>> + Mapping may also fail if the memory is not within the DMA mask of the
>>> + device. However, this constraint does not apply if the platform has
>>> + an IOMMU (a device which maps an I/O DMA address to a physical memory
>>> + address), or the kernel is configured with SWIOTLB (bounce buffers).
>>> + It is reasonable to assume that at least one of these mechanisms
>>> + allows streaming DMA to any physical address.
>
> Now I realize this last sentence may be contentious...
The whole paragraph is wrong as written, not least because it is
conflating two separate things: "any physical address" is objectively
untrue, since SWIOTLB can only bounce from buffers within by the
kernel's linear/direct map, i.e. not highmem, not random memory
carveouts, and and definitely not PAs which are not RAM at all.
Secondly, even if the source buffer *is* bounceable/mappable, there is
still no guarantee at all that it can actually be made to appear at a
DMA address within an arbitrary DMA mask. We aim for a general
expectation that 32-bit DMA masks should be well-supported (but still
not 100% guaranteed), but anything smaller can absolutely still have a
high chance of failing, e.g. due to the SWIOTLB buffer being allocated
too high or limited IOVA space.
> @Marek, @Robin Do you agree that device drivers should not be concerned
> about the physical address of a buffer passed to the streaming DMA API?
>
> I mean, are there any real-world systems with:
> * some RAM that is not DMA-addressable,
> * no IOMMU,
> * CONFIG_SWIOTLB is not set?
Yes, almost certainly, because "DMA-addressable" depends on individual
devices. You can't stop a user from sticking, say, a Broadcom 43xx WiFi
card into a PCI slot on an i.MX6 board with 2GB of RAM that *starts*
just above its 31-bit DMA capability. People are still using AMD Seattle
machines, where even though arm64 does have SWIOTLB it's essentially
useless since RAM starts up around 40 bits IIRC (and although they do
also have SMMUs for PCI, older firmware didn't advertise them).
> FWIW if _I_ received a bug report that a device driver fails to submit
> I/O on such a system, I would politely explain the reporter that their
> kernel is misconfigured, and they should enable CONFIG_SWIOTLB.
It's not really that simple. SWIOTLB, ZONE_DMA, etc. require platform
support, which end users can't just turn on if it's not there to begin with.
Thanks,
Robin.
next prev parent reply other threads:[~2025-06-26 9:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 13:39 [PATCH 0/8] update DMA API documentation Petr Tesarik
2025-06-24 13:39 ` [PATCH 1/8] docs: dma-api: use "DMA API" consistently throughout the document Petr Tesarik
2025-06-25 2:41 ` Randy Dunlap
2025-06-24 13:39 ` [PATCH 2/8] docs: dma-api: replace consistent with coherent Petr Tesarik
2025-06-26 4:51 ` Petr Tesarik
2025-06-26 7:21 ` Marek Szyprowski
2025-06-24 13:39 ` [PATCH 3/8] docs: dma-api: remove remnants of PCI DMA API Petr Tesarik
2025-06-26 1:46 ` Bagas Sanjaya
2025-06-24 13:39 ` [PATCH 4/8] docs: dma-api: add a kernel-doc comment for dma_pool_zalloc() Petr Tesarik
2025-06-24 13:39 ` [PATCH 5/8] docs: dma-api: remove duplicate description of the DMA pool API Petr Tesarik
2025-06-25 2:40 ` Randy Dunlap
2025-06-25 6:41 ` Petr Tesarik
2025-06-24 13:39 ` [PATCH 6/8] docs: dma-api: clarify DMA addressing limitations Petr Tesarik
2025-06-26 1:47 ` Bagas Sanjaya
2025-06-24 13:39 ` [PATCH 7/8] docs: dma-api: update streaming DMA API physical address constraints Petr Tesarik
2025-06-26 1:49 ` Bagas Sanjaya
2025-06-26 5:06 ` Petr Tesarik
2025-06-26 7:09 ` Marek Szyprowski
2025-06-26 8:25 ` Petr Tesarik
2025-06-26 9:58 ` Robin Murphy [this message]
2025-06-26 13:48 ` Petr Tesarik
2025-06-26 16:45 ` Robin Murphy
2025-06-26 19:40 ` Petr Tesarik
2025-06-27 11:07 ` Robin Murphy
2025-06-27 11:32 ` Petr Tesarik
2025-06-27 12:55 ` Christoph Hellwig
2025-06-27 13:02 ` Petr Tesarik
2025-06-27 12:52 ` Christoph Hellwig
2025-06-24 13:39 ` [PATCH 8/8] docs: dma-api: clean up documentation of dma_map_sg() Petr Tesarik
2025-06-26 1:50 ` Bagas Sanjaya
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=bdb3a37a-a9d3-44c1-8eb7-41912c976ad1@arm.com \
--to=robin.murphy@arm.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bagasdotme@gmail.com \
--cc=corbet@lwn.net \
--cc=csander@purestorage.com \
--cc=iommu@lists.linux.dev \
--cc=john.g.garry@oracle.com \
--cc=kbusch@kernel.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=ptesarik@suse.com \
--cc=sagi@grimberg.me \
/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;
as well as URLs for NNTP newsgroup(s).